home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / DCLAP 4j / SeqPups / apps / clustalw.src / amenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-17  |  87.3 KB  |  3,247 lines  |  [TEXT/R*ch]

  1. /* Menus and command line interface for Clustal W  */
  2. /* DES was here MARCH. 1994 */
  3. /* DES was here SEPT.  1994 */
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <ctype.h>
  7. #include <stdlib.h>
  8. #include <signal.h>
  9. #include <setjmp.h>
  10. #include "clustalw.h"
  11. #include "param.h"
  12.  
  13. static jmp_buf jmpbuf;
  14. #define BADSIG (void (*)())-1
  15.  
  16. static void jumper()
  17. {
  18.         longjmp(jmpbuf,1);
  19. }
  20.  
  21.  
  22. /*
  23. *    Prototypes
  24. */
  25.  
  26. extern double countid(int, int);
  27. extern void   *ckalloc(size_t);
  28. extern void   ckfree(void *);
  29. extern void   getstr(char *,char *);
  30. extern double getreal(char *,double,double,double);
  31. extern int    getint(char *,int,int,int);
  32. extern void   do_system(void);
  33. extern int    readseqs(int);
  34. extern void   get_path(char *,char *);
  35. extern void   bootstrap_tree(void);
  36. extern void   error(char *,...);
  37. extern int    SeqGCGCheckSum(char *, int);
  38. extern void   show_pair(void);
  39. extern int    malign(int istart);
  40. extern int    palign1(void);
  41. extern int    palign2(void);
  42. extern void   pairalign(int istart, int iend, int jstart, int jend);
  43. extern int    read_user_matrix(char *, int *, int *);
  44. extern void   guide_tree(void);
  45. extern void   phylogenetic_tree(void);
  46. extern int    read_tree(char *, int, int);
  47. extern int    calc_distances(int);
  48. extern void   clear_tree(treeptr);
  49.  
  50.  
  51.  
  52. void     init_amenu(void);
  53. void     parse_params(void);
  54. void     main_menu(void);
  55. FILE     *open_output_file(char *, char *, char *, char *);
  56. FILE     *open_explicit_file(char *);
  57. #ifdef UNIX
  58. FILE     *open_path(char *);
  59. #endif
  60.  
  61. static int check_param(char *inline1,char *params[], char *param_arg[]);
  62. static int find_match(char *probe, char *list[], int n);
  63. static void get_help(char);            /* Help procedure */
  64. static void show_aln(void);
  65. static void pair_menu(void);
  66. static void multi_menu(void);
  67. static void gap_penalties_menu(void);
  68. static void multiple_align_menu(void);          /* multiple alignments menu */
  69. static void profile_align_menu(void);           /* profile       "      "   */
  70. static void phylogenetic_tree_menu(void);       /* NJ trees/distances menu  */
  71. static int  read_matrix(char **,char *,int, int *, int *);
  72. static Boolean user_mat(char *, int *, int *);
  73. static void seq_input(void);
  74. static void align(void);
  75. static void new_sequence_align(void);
  76. static void make_tree(void);
  77. static void get_tree(void);
  78. static void clustal_out(FILE *, int);
  79. static void nbrf_out(FILE *, int);
  80. static void gcg_out(FILE *, int);
  81. static void phylip_out(FILE *, int);
  82. static void gde_out(FILE *, int);
  83. static Boolean open_alignment_output(char *);
  84. static void create_alignment_output(int);
  85. static void create_parameter_output(void);
  86. static void reset(void);
  87. static void profile_input(int);           /* read a profile */
  88. static void format_options_menu(void);          /* format of alignment output */
  89. static void tree_format_options_menu(void);     /* format of tree output */
  90. static void profile_align(void);                /* Align 2 alignments */
  91.  
  92. /*
  93. *     Global variables
  94. */
  95.  
  96. extern double  **tmat;
  97. extern float    gap_open,      gap_extend;
  98. extern float      dna_gap_open,  dna_gap_extend;
  99. extern float     prot_gap_open, prot_gap_extend;
  100. extern float    pw_go_penalty,      pw_ge_penalty;
  101. extern float      dna_pw_go_penalty,  dna_pw_ge_penalty;
  102. extern float     prot_pw_go_penalty, prot_pw_ge_penalty;
  103. extern float     revision_level;
  104. extern int      wind_gap,ktup,window,signif;
  105. extern int      dna_wind_gap, dna_ktup, dna_window, dna_signif;
  106. extern int      prot_wind_gap,prot_ktup,prot_window,prot_signif;
  107. extern int     boot_ntrials;        /* number of bootstrap trials */
  108. extern int    nseqs;
  109. extern int    new_seq;
  110. extern int     *seqlen_array;
  111. extern int     divergence_cutoff;
  112. extern int     debug;
  113. extern int     neg_matrix;
  114. extern Boolean  quick_pairalign;
  115. extern Boolean    reset_alignments;        /* DES */
  116. extern int     gap_dist;
  117. extern Boolean     no_hyd_penalties, no_pref_penalties;
  118. extern int     first_seq, last_seq;
  119. extern int     max_aa, gap_pos1, gap_pos2;
  120. extern int     *output_index, output_order;
  121. extern int     usermat[], pw_usermat[];
  122. extern int     aa_xref[], pw_aa_xref[];
  123.  
  124. extern Boolean     lowercase; /* Flag for GDE output - set on comm. line*/
  125. extern Boolean     output_clustal, output_nbrf, output_phylip, output_gcg, output_gde;
  126. extern Boolean     output_tree_clustal, output_tree_phylip, output_tree_distances;
  127. extern Boolean     tossgaps, kimura;
  128. extern Boolean  percent;
  129. extern Boolean     explicit_dnaflag;  /* Explicit setting of sequence type on comm.line*/
  130. extern Boolean     explicit_outfile;  /* Explicit setting of output file on comm.line*/
  131. extern Boolean     explicit_treefile; /* Explicit setting of guide file on comm.line*/
  132. extern Boolean     usemenu;
  133. extern Boolean     showaln, save_parameters;
  134. extern Boolean    dnaflag,is_weight;
  135. extern unsigned int boot_ran_seed;
  136.  
  137.  
  138. extern FILE     *tree;
  139. extern FILE     *clustal_outfile, *gcg_outfile, *nbrf_outfile, *phylip_outfile;
  140. extern FILE     *gde_outfile;
  141. extern FILE     *phylip_phy_tree_file;
  142.  
  143. extern char     hyd_residues[];
  144. extern char     *amino_acid_codes;
  145. extern char     *nucleic_acid_order;
  146. extern char     mtrxname[], pw_mtrxname[];
  147. extern char     *paramstr;
  148. extern char    seqname[];
  149. extern char     phylip_phy_tree_name[];
  150. extern char     **seq_array;
  151. extern char     **names, **titles;
  152.  
  153. static char     outfile_name[FILENAMELEN+1];
  154. static char     clustal_outname[FILENAMELEN+1], gcg_outname[FILENAMELEN+1];
  155. static char      phylip_outname[FILENAMELEN+1],nbrf_outname[FILENAMELEN+1];
  156. static char      gde_outname[FILENAMELEN+1];
  157.  
  158. static char      profile1_name[FILENAMELEN+1];
  159. static char      profile2_name[FILENAMELEN+1];
  160.  
  161. static int numparams;
  162. static char *params[MAXARGS];
  163. static char *param_arg[MAXARGS];
  164.  
  165. static char *cmd_line_type[] = {
  166.                 " ",
  167.                 "=n ",
  168.                 "=f ",
  169.                 "=string ",
  170.                 "=filename ",
  171.                 ""};
  172.  
  173. static char *matrix_txt[] = {
  174.                 "BLOSUM series",
  175.                 "PAM series",
  176.                 "Identity matrix",
  177.                 "user defined"   };
  178.  
  179. static char *pw_matrix_txt[] = {
  180.                 "BLOSUM30",
  181.                 "PAM350",
  182.                 "Identity matrix",
  183.                 "user defined"   };
  184.  
  185. int     profile1_nseqs;           /* have been filled; the no. of seqs in prof 1*/
  186. Boolean empty;
  187. Boolean profile1_empty, profile2_empty;   /* whether or not profiles   */
  188.  
  189. char *lin1, *lin2, *lin3;
  190.  
  191. void init_amenu(void)
  192. {
  193.     empty=TRUE;
  194.      
  195.     profile1_empty = TRUE;     /*  */
  196.     profile2_empty = TRUE;     /*  */
  197.  
  198.     lin1 = (char *)ckalloc( (MAXLINE+1) * sizeof (char) );
  199.     lin2 = (char *)ckalloc( (MAXLINE+1) * sizeof (char) );
  200.     lin3 = (char *)ckalloc( (MAXLINE+1) * sizeof (char) );
  201. }
  202.  
  203.  
  204.  
  205.  
  206. static int check_param(char *inline1,char *params[], char *param_arg[])
  207. {
  208.  
  209.         char    *inptr;
  210. #ifndef MAC
  211.         char *strtok(char *s1, const char *s2);
  212. #endif
  213.         int     temp,len,i,j,n,match;
  214.     int     name1 = FALSE;
  215.  
  216.     if (inline1[0] != '/') name1 = TRUE;
  217.  
  218.         inptr=inline1;
  219.         for (i=0;i<MAXARGS;i++) {
  220.                 if ((params[i]=strtok(inptr,"/"))==NULL)
  221.                         break;
  222.                 inptr=NULL;
  223.         }
  224.         if (i==MAXARGS) {
  225.         fprintf(stderr,"Error: too many command line arguments\n");
  226.          return(-1);
  227.     }
  228.  
  229.     n = i;
  230.         for (i=0;i<n;i++) {
  231.                 param_arg[i] = NULL;
  232.         len = strlen(params[i]);
  233.         for(j=0; j<len; j++)
  234.             if(params[i][j] == '=') {
  235.                 param_arg[i] = (char *)ckalloc((len-j) * sizeof(char));
  236.                 strncpy(param_arg[i],¶ms[i][j+1],len-j-1);
  237.                 params[i][j] = EOS;
  238.                 param_arg[i][len-j-1] = EOS;
  239.                 break;
  240.             }
  241. /*
  242.     search the parameter list for a match 
  243. */
  244.         if ((i==0) && (name1 == TRUE)) continue;
  245.         j = 0;
  246.         match = -1;
  247.         for(;;) {
  248.             if (cmd_line[j].str[0] == '\0') break;
  249.             if (!strcmp(params[i],cmd_line[j].str)) {
  250.                 match = j;
  251.                 *cmd_line[match].flag = i;
  252.                 if ((cmd_line[match].type != NOARG) &&
  253.                                     (param_arg[i] == NULL)) {
  254.                     fprintf(stderr,
  255.                                         "Error: parameter required for /%s\n",params[i]);
  256.                     exit(1);
  257.                 }
  258.                 break;
  259.             }
  260.             j++;
  261.         }
  262.         if (match == -1) {
  263.             fprintf(stderr,
  264.                         "Error: unknown option /%s\n",params[i]);
  265.             exit(1);
  266.         }
  267.     }
  268.  
  269.         return(n);
  270. }
  271.  
  272.  
  273.  
  274. #ifdef UNIX
  275. FILE *open_path(char *fname)  /* to open in read-only file fname searching for 
  276.                  it through all path directories */
  277. {
  278. #define Mxdir 70
  279.         char dir[Mxdir+1], *path, *deb, *fin;
  280.         FILE *fich;
  281.         int lf, ltot;
  282.  
  283.         path=getenv("PATH");     /* get the list of path directories, 
  284.                     separated by :
  285.                     */
  286.         if (path == NULL ) return fopen(fname,"r");
  287.         lf=strlen(fname);
  288.         deb=path;
  289.         do
  290.                 {
  291.                 fin=strchr(deb,':');
  292.                 if(fin!=NULL)
  293.                         { strncpy(dir,deb,fin-deb); ltot=fin-deb; }
  294.                 else
  295.                         { strcpy(dir,deb); ltot=strlen(dir); }
  296.                 /* now one directory is in string dir */
  297.                 if( ltot + lf + 1 <= Mxdir)
  298.                         {
  299.                         dir[ltot]='/';
  300.                         strcpy(dir+ltot+1,fname); /* now dir is appended with fi
  301.    lename */
  302.                         if( (fich = fopen(dir,"r") ) != NULL) break;
  303.                         }
  304.                 else fich = NULL;
  305.                 deb=fin+1;
  306.                 }
  307.         while (fin != NULL);
  308.         return fich;
  309. }
  310. #endif
  311.  
  312.  
  313. static void get_help(char help_pointer)    /* Help procedure */
  314. {    
  315.     FILE *help_file;
  316.     int  i, number, nlines;
  317.     Boolean found_help;
  318.     char temp[MAXLINE+1];
  319.     char token;
  320.     char *digits = "0123456789ABCD";
  321.     char *help_marker    = ">>HELP";
  322.  
  323. #ifdef MSDOS
  324.     char *help_file_name = "clustalw.hlp";
  325. #else
  326.     char *help_file_name = "clustalw_help";
  327. #endif
  328.  
  329.  
  330. #ifdef VMS
  331.         if((help_file=fopen(help_file_name,"r","rat=cr","rfm=var"))==NULL) {
  332.             error("Cannot open help file [%s]",help_file_name);
  333.             return;
  334.         }
  335. #else
  336.  
  337. #ifdef UNIX
  338.         if((help_file=open_path(help_file_name))==NULL) {
  339.              if((help_file=fopen(help_file_name,"r"))==NULL) {
  340.                   error("Cannot open help file [%s]",help_file_name);
  341.                   return;
  342.              }
  343.         }
  344. #else
  345.         if((help_file=fopen(help_file_name,"r"))==NULL) {
  346.             error("Cannot open help file [%s]",help_file_name);
  347.             return;
  348.         }
  349. #endif
  350.  
  351. #endif
  352. /*        error("Cannot open help file [%s]",help_file_name);
  353.         return;
  354.     }
  355. */
  356.     nlines = 0;
  357.     number = -1;
  358.     found_help = FALSE;
  359.  
  360.     while(TRUE) {
  361.         if(fgets(temp,MAXLINE+1,help_file) == NULL) {
  362.             if(!found_help)
  363.                 error("No help found in help file");
  364.             fclose(help_file);
  365.             return;
  366.         }
  367.         if(strstr(temp,help_marker)) {
  368.                         token = ' ';
  369.             for(i=0; i<8; i++)
  370.                 if(strchr(digits, temp[i])) {
  371.                     token = temp[i];
  372.                     break;
  373.                 }
  374.         }
  375.         if(token == help_pointer) {
  376.             found_help = TRUE;
  377.             while(fgets(temp,MAXLINE+1,help_file)) {
  378.                 if(strstr(temp, help_marker)){
  379.                       if(usemenu) {
  380.                         fprintf(stdout,"\n");
  381.                             getstr("Press [RETURN] to continue",lin2);
  382.                       }
  383.                     fclose(help_file);
  384.                     return;
  385.                 }
  386.                    fputs(temp,stdout);
  387.                    ++nlines;
  388.                    if(usemenu) {
  389.                       if(nlines >= PAGE_LEN) {
  390.                             fprintf(stdout,"\n");
  391.                           getstr("Press [RETURN] to continue or  X  to stop",lin2);
  392.                          if(toupper(*lin2) == 'X') {
  393.                            fclose(help_file);
  394.                            return;
  395.                          }
  396.                          else
  397.                            nlines = 0;
  398.                    }
  399.                    }
  400.             }
  401.             if(usemenu) {
  402.                 fprintf(stdout,"\n");
  403.                 getstr("Press [RETURN] to continue",lin2);
  404.             }
  405.             fclose(help_file);
  406.         }
  407.     }
  408. }
  409.  
  410. static void show_aln(void)         /* Alignment screen display procedure */
  411. {
  412.         FILE *file;
  413.         int  i, nlines;
  414.         char temp[MAXLINE+1];
  415.         char file_name[FILENAMELEN+1];
  416.  
  417.         if(output_clustal) strcpy(file_name,clustal_outname);
  418.         else if(output_nbrf) strcpy(file_name,nbrf_outname);
  419.         else if(output_gcg) strcpy(file_name,gcg_outname);
  420.         else if(output_phylip) strcpy(file_name,phylip_outname);
  421.         else if(output_gde) strcpy(file_name,gde_outname);
  422.  
  423. #ifdef VMS
  424.     if((file=fopen(file_name,"r","rat=cr","rfm=var"))==NULL) {
  425. #else
  426.     if((file=fopen(file_name,"r"))==NULL) {
  427. #endif
  428.                 error("Cannot open file [%s]",file_name);
  429.                 return;
  430.         }
  431.  
  432.         fprintf(stdout,"\n\n");
  433.         nlines = 0;
  434.  
  435.         while(fgets(temp,MAXLINE+1,file)) {
  436.                 fputs(temp,stdout);
  437.                 ++nlines;
  438.                 if(nlines >= PAGE_LEN) {
  439.                         fprintf(stdout,"\n");
  440.                         getstr("Press [RETURN] to continue or  X  to stop",lin2);
  441.                         if(toupper(*lin2) == 'X') {
  442.                                 fclose(file);
  443.                                 return;
  444.                         }
  445.                         else
  446.                                 nlines = 0;
  447.                 }
  448.         }
  449.         fclose(file);
  450.         fprintf(stdout,"\n");
  451.         getstr("Press [RETURN] to continue",lin2);
  452. }
  453.  
  454.  
  455. void parse_params()
  456. {
  457.     char path[FILENAMELEN+1];
  458.     int i,j,k,c,len,lenp,temp;
  459.     float ftemp;
  460.  
  461.     Boolean do_align, do_align_only, do_tree_only, do_tree, do_boot, do_profile, do_something;
  462.     fprintf(stdout,"\n\n\n");
  463.     fprintf(stdout," CLUSTAL W(%2.1f) Multiple Sequence Alignments\n\n\n", revision_level);
  464.  
  465.     do_align = do_align_only = do_tree_only = do_tree = do_boot = do_profile = do_something = FALSE;
  466.  
  467.     *seqname=EOS;
  468.  
  469.     len=strlen(paramstr);
  470.     for(i=0;i<len;++i) paramstr[i]=tolower(paramstr[i]);
  471.  
  472.         numparams = check_param(paramstr, params, param_arg);
  473.     if (numparams <0) exit(1);
  474.  
  475.     if(sethelp != -1) {
  476.         get_help('9');
  477.         exit(1);
  478.     }
  479.  
  480.     if(setoptions != -1) {
  481.         fprintf(stderr,"clustalw option list:-\n");
  482.         for (i=0;cmd_line[i].str[0] != '\0';i++) {
  483.             fprintf(stderr,"\t\t/%s%s",cmd_line[i].str,cmd_line_type[cmd_line[i].type]);
  484.             if (cmd_line[i].type == OPTARG) {
  485.                 if (cmd_line[i].arg[0][0] != '\0')
  486.                     fprintf(stderr,"=%s",cmd_line[i].arg[0]);
  487.                 for (j=1;cmd_line[i].arg[j][0] != '\0';j++)
  488.                     fprintf(stderr," OR %s",cmd_line[i].arg[j]);
  489.             }
  490.             fprintf(stderr,"\n");
  491.         }
  492.         exit(1);
  493.     }
  494.  
  495.  
  496. /*****************************************************************************/
  497. /*  Check to see if sequence type is explicitely stated..override ************/
  498. /* the automatic checking (DNA or Protein).   /type=d or /type=p *************/
  499. /*****************************************************************************/
  500.     if(settype != -1)
  501.         if(strlen(param_arg[settype])>0) {
  502.             temp = find_match(param_arg[settype],type_arg,2);
  503.             if(temp == 0) {
  504.                 dnaflag = FALSE;
  505.                 explicit_dnaflag = TRUE;
  506.                 fprintf(stdout,
  507.                 "\nSequence type explicitly set to Protein\n");
  508.             }
  509.             else if(temp == 1) {
  510.                 fprintf(stdout,
  511.                 "\nSequence type explicitly set to DNA\n");
  512.                 dnaflag = TRUE;
  513.                 explicit_dnaflag = TRUE;
  514.             }
  515.             else
  516.                 fprintf(stdout,"\nUnknown sequence type %s\n",
  517.                 param_arg[settype]);
  518.         }
  519.  
  520.  
  521. /***************************************************************************
  522. *   check to see if 1st parameter does not start with '/' i.e. look for an *
  523. *   input file as first parameter.   The input file can also be specified  *
  524. *   by /infile=fname.                                                      *
  525. ****************************************************************************/
  526.  
  527.     if(paramstr[0] != '/') {
  528.         strcpy(seqname, params[0]);
  529.     }
  530.  
  531. /**************************************************/
  532. /*  Look for /infile=file.ext on the command line */
  533. /**************************************************/
  534.  
  535.     if(setinfile != -1) {
  536.         if(strlen(param_arg[setinfile]) <= 0) {
  537.             error("Bad sequence file name");
  538.             exit(1);
  539.         }
  540.         strcpy(seqname, param_arg[setinfile]);
  541.     }
  542.  
  543.     if(*seqname != EOS) {
  544.         nseqs = readseqs(1);
  545.         if(nseqs < 2) {
  546.                     fprintf(stderr,
  547.             "\nNo. of seqs. read = %d. No alignment!\n",(pint)nseqs);
  548.             exit(1);
  549.         }
  550.         for(i = 1; i<=nseqs; i++) 
  551.             fprintf(stdout,"Sequence %d: %-*s   %6.d %s\n",
  552.             (pint)i,MAXNAMES,names[i],(pint)seqlen_array[i],dnaflag?"bp":"aa");
  553.         empty = FALSE;
  554.                 first_seq = 1;
  555.                 last_seq = nseqs;
  556.         do_something = TRUE;
  557.     }
  558.  
  559. /*********************************************************/
  560. /* Look for /profile1=file.ext  AND  /profile2=file2.ext */
  561. /* You must give both file names OR neither.             */
  562. /*********************************************************/
  563.  
  564.     if(setprofile1 != -1) {
  565.         if(strlen(param_arg[setprofile1]) <= 0) {
  566.             error("Bad profile 1 file name");
  567.             exit(1);
  568.         }
  569.         strcpy(seqname, param_arg[setprofile1]);
  570.         profile_input(1);
  571.         if(nseqs <= 0) 
  572.             exit(1);
  573.     }
  574.  
  575.     if(setprofile2 != -1) {
  576.         if(strlen(param_arg[setprofile2]) <= 0) {
  577.             error("Bad profile 2 file name");
  578.             exit(1);
  579.         }
  580.         if(profile1_empty) {
  581.             error("Only 1 profile file (profile 2) specified.");
  582.             exit(1);
  583.         }
  584.         strcpy(seqname, param_arg[setprofile2]);
  585.         profile_input(2);
  586.         if(nseqs > profile1_nseqs) 
  587.             do_something = do_profile = TRUE;
  588.         else {
  589.             error("No sequences read from profile 2");
  590.             exit(1);
  591.         }
  592.     }
  593.  
  594. /*************************************************************************/
  595. /* Look for /tree or /bootstrap or /align or /usetree ******************/
  596. /*************************************************************************/
  597.  
  598.     if (setinteractive != -1) {
  599.         settree = -1;
  600.         setbootstrap = -1;
  601.         setalign = -1;
  602.         setusetree = -1;
  603.         setnewtree = -1;
  604.     }
  605.  
  606.     if(settree != -1 )
  607.         if(empty) {
  608.             error("Cannot draw tree.  No input alignment file");
  609.             exit(1);
  610.         }
  611.         else 
  612.             do_tree = TRUE;
  613.  
  614.     if(setbootstrap != -1)
  615.         if(empty) {
  616.             error("Cannot bootstrap tree. No input alignment file");
  617.             exit(1);
  618.         }
  619.         else {
  620.             temp = 0;
  621.             if(strlen(param_arg[setbootstrap]) > 0)
  622.                  sscanf(param_arg[setbootstrap],"%d",&temp);
  623.             if(temp > 0)          boot_ntrials = temp;
  624.             do_boot = TRUE;
  625.         }
  626.  
  627.     if(setalign != -1)
  628.         if(empty) {
  629.             error("Cannot align sequences.  No input file");
  630.             exit(1);
  631.         }
  632.         else 
  633.             do_align = TRUE;
  634.  
  635.     if(setusetree != -1)
  636.         if(empty) {
  637.             error("Cannot align sequences.  No input file");
  638.             exit(1);
  639.         }
  640.         else  {
  641.                 if(strlen(param_arg[setusetree]) == 0) {
  642.                 error("Cannot align sequences.  No tree file specified");
  643.                 exit(1);
  644.                 }
  645.                         else {
  646.                     strcpy(phylip_phy_tree_name, param_arg[setusetree]);
  647.                 }
  648.                 do_align_only = TRUE;
  649.         }
  650.  
  651.     if(setnewtree != -1)
  652.         if(empty) {
  653.             error("Cannot align sequences.  No input file");
  654.             exit(1);
  655.         }
  656.         else  {
  657.                 if(strlen(param_arg[setnewtree]) == 0) {
  658.                 error("Cannot align sequences.  No tree file specified");
  659.                 exit(1);
  660.                 }
  661.                         else {
  662.                     strcpy(phylip_phy_tree_name, param_arg[setnewtree]);
  663.                 explicit_treefile = TRUE;
  664.                 }
  665.             do_tree_only = TRUE;
  666.         }
  667.  
  668.     if( (!do_tree) && (!do_boot) && (!empty) && (!do_profile) && (!do_align_only) && (!do_tree_only)) 
  669.         do_align = TRUE;
  670.  
  671.     if(!do_something && (setinteractive == -1)) {
  672.         error("No input file(s) specified");
  673.         exit(1);
  674.     }
  675.  
  676. /*** ? /quicktree  */
  677.         if(setquicktree != -1)
  678.         quick_pairalign = TRUE;
  679.  
  680.     
  681.     if(dnaflag) {
  682.         gap_open   = dna_gap_open;
  683.         gap_extend = dna_gap_extend;
  684.         pw_go_penalty  = dna_pw_go_penalty;
  685.         pw_ge_penalty  = dna_pw_ge_penalty;
  686.                 ktup       = dna_ktup;
  687.                 window     = dna_window;
  688.                 signif     = dna_signif;
  689.                 wind_gap   = dna_wind_gap;
  690.  
  691.     }
  692.     else {
  693.         gap_open   = prot_gap_open;
  694.         gap_extend = prot_gap_extend;
  695.         pw_go_penalty  = prot_pw_go_penalty;
  696.         pw_ge_penalty  = prot_pw_ge_penalty;
  697.                 ktup       = prot_ktup;
  698.                 window     = prot_window;
  699.                 signif     = prot_signif;
  700.                 wind_gap   = prot_wind_gap;
  701.     }
  702.  
  703.  
  704. /****************************************************************************/
  705. /* look for parameters on command line  e.g. gap penalties, k-tuple etc.    */
  706. /****************************************************************************/
  707.  
  708. /*** ? /score=percent or /score=absolute */
  709.         if(setscore != -1)
  710.                 if(strlen(param_arg[setscore]) > 0) {
  711.             temp = find_match(param_arg[setscore],score_arg,2);
  712.                         if(temp == 0)
  713.                                 percent = TRUE;
  714.                         else if(temp == 1)
  715.                                 percent = FALSE;
  716.                         else
  717.                                 fprintf(stdout,"\nUnknown SCORE type: %s\n",
  718.                                 param_arg[setscore]);
  719.                 }
  720.  
  721. /*** ? /seed=n */
  722.         if(setseed != -1) {
  723.                 temp = 0;
  724.                 if(strlen(param_arg[setseed]) > 0)
  725.                          sscanf(param_arg[setseed],"%d",&temp);
  726.                 if(temp > 0) boot_ran_seed = temp;
  727.         fprintf(stdout,"\ntemp = %d; seed = %u;\n",(pint)temp,boot_ran_seed);
  728.         }
  729.  
  730.  
  731.  
  732.  
  733. /*** ? /output=PIR, GCG, GDE or PHYLIP  Only 1 can be switched on at a time */
  734.     if(setoutput != -1)
  735.         if(strlen(param_arg[setoutput]) > 0) {
  736.             temp = find_match(param_arg[setoutput],output_arg,4);
  737.             switch (temp) {
  738.                 case 0: /* GCG */
  739.                     output_gcg     = TRUE;
  740.                     output_clustal = FALSE;
  741.                     break;
  742.                 case 1: /* GDE */
  743.                     output_gde     = TRUE;
  744.                     output_clustal = FALSE;
  745.                     break;
  746.                 case 2: /* PIR */
  747.                     output_nbrf    = TRUE;
  748.                     output_clustal = FALSE;
  749.                     break;
  750.                 case 3: /* PHYLIP */
  751.                     output_phylip  = TRUE;
  752.                     output_clustal = FALSE;
  753.                     break;
  754.                 default:
  755.                     fprintf(stdout,"\nUnknown OUTPUT type: %s\n",
  756.                     param_arg[setoutput]);
  757.             }
  758.         }
  759.  
  760. /*** ? /outputtree=NJ or PHYLIP or DIST Only 1 can be switched on at a time */
  761.     if(setoutputtree != -1)
  762.         if(strlen(param_arg[setoutputtree]) > 0) {
  763.             temp = find_match(param_arg[setoutputtree],outputtree_arg,3);
  764.             switch (temp) {
  765.                 case 0: /* NJ */
  766.                     output_tree_clustal = TRUE;
  767.                     output_tree_phylip = FALSE;
  768.                     output_tree_distances = FALSE;
  769.                     break;
  770.                 case 1: /* PHYLIP */
  771.                     output_tree_phylip  = TRUE;
  772.                     output_tree_clustal = FALSE;
  773.                     output_tree_distances = FALSE;
  774.                     break;
  775.                 case 2: /* PHYLIP */
  776.                     output_tree_distances = TRUE;
  777.                     output_tree_phylip  = FALSE;
  778.                     output_tree_clustal = FALSE;
  779.                     break;
  780.                 default:
  781.                     fprintf(stdout,"\nUnknown OUTPUT TREE type: %s\n",
  782.                     param_arg[setoutputtree]);
  783.             }
  784.         }
  785.  
  786. /*** ? /ktuple=n */
  787.         if(setktuple != -1) {
  788.                 temp = 0;
  789.                 if(strlen(param_arg[setktuple]) > 0)
  790.              sscanf(param_arg[setktuple],"%d",&temp);
  791.                 if(temp > 0) {
  792.                         if(dnaflag) {
  793.                                 if(temp <= 4) {
  794.                                         ktup         = temp;
  795.                                         dna_ktup     = ktup;
  796.                                         wind_gap     = ktup + 4;
  797.                                         dna_wind_gap = wind_gap;
  798.                                 }
  799.                         }
  800.                         else {
  801.                                 if(temp <= 2) {
  802.                                         ktup          = temp;
  803.                                         prot_ktup     = ktup;
  804.                                         wind_gap      = ktup + 3;
  805.                                         prot_wind_gap = wind_gap;
  806.                                 }
  807.                         }
  808.                 }
  809.         }
  810.  
  811. /*** ? /pairgap=n */
  812.         if(setpairgap != -1) {
  813.                 temp = 0;
  814.                 if(strlen(param_arg[setpairgap]) > 0)
  815.              sscanf(param_arg[setpairgap],"%d",&temp);
  816.                 if(temp > 0)
  817.                         if(dnaflag) {
  818.                                 if(temp > ktup) {
  819.                                         wind_gap     = temp;
  820.                                         dna_wind_gap = wind_gap;
  821.                                 }
  822.                         }
  823.                         else {
  824.                                 if(temp > ktup) {
  825.                                         wind_gap      = temp;
  826.                                         prot_wind_gap = wind_gap;
  827.                                 }
  828.                         }
  829.         }
  830.  
  831.  
  832. /*** ? /topdiags=n   */
  833.         if(settopdiags != -1) {
  834.                 temp = 0;
  835.                 if(strlen(param_arg[settopdiags]) > 0)
  836.              sscanf(param_arg[settopdiags],"%d",&temp);
  837.                 if(temp > 0)
  838.                         if(dnaflag) {
  839.                                 if(temp > ktup) {
  840.                                         signif       = temp;
  841.                                         dna_signif   = signif;
  842.                                 }
  843.                         }
  844.                         else {
  845.                                 if(temp > ktup) {
  846.                                         signif        = temp;
  847.                                         prot_signif   = signif;
  848.                                 }
  849.                         }
  850.         }
  851.  
  852.  
  853. /*** ? /window=n  */
  854.         if(setwindow != -1) {
  855.                 temp = 0;
  856.                 if(strlen(param_arg[setwindow]) > 0)
  857.              sscanf(param_arg[setwindow],"%d",&temp);
  858.                 if(temp > 0)
  859.                         if(dnaflag) {
  860.                                 if(temp > ktup) {
  861.                                         window       = temp;
  862.                                         dna_window   = window;
  863.                                 }
  864.                         }
  865.                         else {
  866.                                 if(temp > ktup) {
  867.                                         window        = temp;
  868.                                         prot_window   = window;
  869.                                 }
  870.                         }
  871.         }
  872.  
  873. /*** ? /transitions */
  874.     if(settransitions != -1)
  875.         is_weight = FALSE;
  876.  
  877. /*** ? /kimura */
  878.     if(setkimura != -1)
  879.         kimura = TRUE;
  880.  
  881. /*** ? /tossgaps */
  882.     if(settossgaps != -1)
  883.         tossgaps = TRUE;
  884.  
  885.  
  886. /*** ? /negative  */
  887.     if(setnegative != -1)
  888.         neg_matrix = TRUE;
  889.  
  890.  
  891. /*** ? /pwmatrix=ID (user's file)  */
  892.     if(setpwmatrix != -1)
  893.         if(strlen(param_arg[setpwmatrix]) > 0) {
  894.                         if (strcmp(param_arg[setpwmatrix],"blosum")==0) {
  895.                                 strcpy(pw_mtrxname, param_arg[setpwmatrix]);
  896.                                 pw_matnum = 1;
  897.                         }
  898.                         else if (strcmp(param_arg[setpwmatrix],"pam")==0) {
  899.                                 strcpy(pw_mtrxname, param_arg[setpwmatrix]);
  900.                                 pw_matnum = 2;
  901.                         }
  902.                         else if (strcmp(param_arg[setpwmatrix],"id")==0) {
  903.                                 strcpy(pw_mtrxname, param_arg[setpwmatrix]);
  904.                                 pw_matnum = 3;
  905.                         }
  906.             else {
  907.                                 if(user_mat(param_arg[setpwmatrix], pw_usermat, pw_aa_xref))
  908.                                   {
  909.                                      strcpy(pw_mtrxname,param_arg[setpwmatrix]);
  910.                                      pw_matnum=4;
  911.                                   }
  912.                 else exit(1);
  913.             }
  914.  
  915.         }
  916.  
  917.  
  918. /*** ? /matrix=ID (user's file)  */
  919.     if(setmatrix != -1)
  920.         if(strlen(param_arg[setmatrix]) > 0) {
  921.                         if (strcmp(param_arg[setmatrix],"blosum")==0) {
  922.                                 strcpy(mtrxname, param_arg[setmatrix]);
  923.                                 matnum = 1;
  924.                         }
  925.                         else if (strcmp(param_arg[setmatrix],"pam")==0) {
  926.                                 strcpy(mtrxname, param_arg[setmatrix]);
  927.                                 matnum = 2;
  928.                         }
  929.                         else if (strcmp(param_arg[setmatrix],"id")==0) {
  930.                                 strcpy(mtrxname, param_arg[setmatrix]);
  931.                                 matnum = 3;
  932.                         }
  933.             else {
  934.                                 if(user_mat(param_arg[setmatrix], usermat, aa_xref))
  935.                                   {
  936.                                      strcpy(mtrxname,param_arg[setmatrix]);
  937.                                      matnum=4;
  938.                                   }
  939.                 else exit(1);
  940.             }
  941.  
  942.         }
  943.  
  944. /*** ? /maxdiv= n */
  945.     if(setmaxdiv != -1) {
  946.         temp = 0;
  947.         if(strlen(param_arg[setmaxdiv]) > 0)
  948.             sscanf(param_arg[setmaxdiv],"%d",&temp);
  949.         if (temp >= 0)
  950.             divergence_cutoff = temp;
  951.     }
  952.  
  953. /*** ? /gapdist= n */
  954.     if(setgapdist != -1) {
  955.         temp = 0;
  956.         if(strlen(param_arg[setgapdist]) > 0)
  957.             sscanf(param_arg[setgapdist],"%d",&temp);
  958.         if (temp >= 0)
  959.             gap_dist = temp;
  960.     }
  961.  
  962. /*** ? /debug= n */
  963.     if(setdebug != -1) {
  964.         temp = 0;
  965.         if(strlen(param_arg[setdebug]) > 0)
  966.             sscanf(param_arg[setdebug],"%d",&temp);
  967.         if (temp >= 0)
  968.             debug = temp;
  969.     }
  970.  
  971. /*** ? /outfile= (user's file)  */
  972.     if(setoutfile != -1)
  973.         if(strlen(param_arg[setoutfile]) > 0) {
  974.             explicit_outfile = TRUE;
  975.                         strcpy(outfile_name, param_arg[setoutfile]);
  976.         }
  977.  
  978. /*** ? /case= lower/upper  */
  979.     if(setcase != -1) 
  980.         if(strlen(param_arg[setcase]) > 0) {
  981.             temp = find_match(param_arg[setcase],case_arg,2);
  982.             if(temp == 0) {
  983.                 lowercase = TRUE;
  984.             }
  985.             else if(temp = 1) {
  986.                 lowercase = FALSE;
  987.             }
  988.             else
  989.                 fprintf(stdout,"\nUnknown case %s\n",
  990.                 param_arg);
  991.         }
  992.  
  993.  
  994. /*** ? /gapopen=n  */
  995.     if(setgapopen != -1) {
  996.         ftemp = 0.0;
  997.         if(strlen(param_arg[setgapopen]) > 0)
  998.             sscanf(param_arg[setgapopen],"%f",&ftemp);
  999.         if(ftemp >= 0.0)
  1000.             if(dnaflag) {
  1001.                     gap_open     = ftemp;
  1002.                     dna_gap_open = gap_open;
  1003.             }
  1004.             else {
  1005.                     gap_open      = ftemp;
  1006.                     prot_gap_open = gap_open;
  1007.             }
  1008.     }
  1009.  
  1010.  
  1011. /*** ? /gapext=n   */
  1012.     if(setgapext != -1) {
  1013.         ftemp = 0.0;
  1014.         if(strlen(param_arg[setgapext]) > 0)
  1015.             sscanf(param_arg[setgapext],"%f",&ftemp);
  1016.         if(ftemp >= 0)
  1017.             if(dnaflag) {
  1018.                     gap_extend      = ftemp;
  1019.                     dna_gap_extend  = gap_extend;
  1020.             }
  1021.             else {
  1022.                     gap_extend      = ftemp;
  1023.                     prot_gap_extend = gap_extend;
  1024.             }
  1025.     }
  1026.  
  1027. /*** ? /pwgapopen=n  */
  1028.     if(setpwgapopen != -1) {
  1029.         ftemp = 0.0;
  1030.         if(strlen(param_arg[setpwgapopen]) > 0)
  1031.             sscanf(param_arg[setpwgapopen],"%f",&ftemp);
  1032.         if(ftemp >= 0.0)
  1033.             if(dnaflag) {
  1034.                     pw_go_penalty  = ftemp;
  1035.                                         dna_pw_go_penalty = pw_go_penalty;
  1036.             }
  1037.             else {
  1038.                     pw_go_penalty  = ftemp;
  1039.                                         prot_pw_go_penalty = pw_go_penalty;
  1040.             }
  1041.     }
  1042.  
  1043.  
  1044. /*** ? /gapext=n   */
  1045.     if(setpwgapext != -1) {
  1046.         ftemp = 0.0;
  1047.         if(strlen(param_arg[setpwgapext]) > 0)
  1048.             sscanf(param_arg[setpwgapext],"%f",&ftemp);
  1049.         if(ftemp >= 0)
  1050.             if(dnaflag) {
  1051.                     pw_ge_penalty  = ftemp;
  1052.                                         dna_pw_ge_penalty = pw_ge_penalty;
  1053.             }
  1054.             else {
  1055.                     pw_ge_penalty  = ftemp;
  1056.                                         prot_pw_ge_penalty = pw_ge_penalty;
  1057.             }
  1058.     }
  1059.  
  1060.  
  1061.  
  1062. /*** ? /outorder=n  */
  1063.     if(setoutorder != -1) {
  1064.         if(strlen(param_arg[setoutorder]) > 0)
  1065.             temp = find_match(param_arg[setoutorder],outorder_arg,2);
  1066.             if(temp == 0)  {    
  1067.                 output_order   = INPUT;
  1068.             }
  1069.             else if(temp == 1)  {    
  1070.                 output_order   = ALIGNED;
  1071.             }
  1072.             else
  1073.                 fprintf(stdout,"\nUnknown OUTPUT ORDER type %s\n",
  1074.                 param_arg[setoutorder]);
  1075.     }
  1076.  
  1077. /*** ? /endgaps */
  1078.     if(setuseendgaps != -1)
  1079.         use_endgaps = FALSE;
  1080.  
  1081. /*** ? /nopgap  */
  1082.     if(setnopgap != -1)
  1083.         no_pref_penalties = TRUE;
  1084.  
  1085. /*** ? /nohgap  */
  1086.     if(setnohgap != -1)
  1087.         no_hyd_penalties = TRUE;
  1088.  
  1089. /*** ? /hgapresidues="string"  */
  1090.     if(sethgapres != -1)
  1091.         if(strlen(param_arg[sethgapres]) > 0) {
  1092.             for (i=0;i<strlen(hyd_residues) && i<26;i++) {
  1093.                 c = param_arg[sethgapres][i];
  1094.                 if (isalpha(c))
  1095.                     hyd_residues[i] = (char)toupper(c);
  1096.                 else
  1097.                     break;
  1098.             }
  1099.         }
  1100.  
  1101. /****************************************************************************/
  1102. /* Now do whatever has been requested ***************************************/
  1103. /****************************************************************************/
  1104.  
  1105.     if(setinteractive != -1) {
  1106.         usemenu = TRUE;
  1107.         return;
  1108.     }
  1109.  
  1110.     if(do_profile)
  1111.         profile_align();
  1112.  
  1113.     else if(do_align)
  1114.         align();
  1115.  
  1116.         else if (do_align_only)
  1117.                 get_tree();
  1118.  
  1119.     else if(do_tree_only)
  1120.         make_tree();
  1121.  
  1122.     else if(do_tree)
  1123.         phylogenetic_tree();
  1124.  
  1125.     else if(do_boot)
  1126.         bootstrap_tree();
  1127.  
  1128.     exit(1);
  1129.  
  1130. /*******whew!***now*go*home****/
  1131. }
  1132.  
  1133.  
  1134.  
  1135.  
  1136.  
  1137.  
  1138.  
  1139. void main_menu(void)
  1140. {
  1141.         void jumper();
  1142.         int catchint;
  1143.  
  1144.         catchint = signal(SIGINT, SIG_IGN) != SIG_IGN;
  1145.         if (catchint) {
  1146.                 if (setjmp(jmpbuf) != 0)
  1147.                         fprintf(stderr,"\n.. Interrupt\n");
  1148. #ifdef UNIX
  1149.                 if (signal(SIGINT,jumper) == BADSIG)
  1150.                         fprintf(stderr,"Error: signal\n");
  1151. #else
  1152.                 if (signal(SIGINT,SIG_DFL) == BADSIG)
  1153.                         fprintf(stderr,"Error: signal\n");
  1154. #endif
  1155.         }
  1156.  
  1157.     while(TRUE) {
  1158.         fprintf(stdout,"\n\n\n");
  1159.         fprintf(stdout," **************************************************************\n");
  1160.         fprintf(stdout," ******** CLUSTAL W(%2.1f) Multiple Sequence Alignments  ********\n",revision_level);
  1161.         fprintf(stdout," **************************************************************\n");
  1162.         fprintf(stdout,"\n\n");
  1163.         
  1164.         fprintf(stdout,"     1. Sequence Input From Disc\n");
  1165.         fprintf(stdout,"     2. Multiple Alignments\n");
  1166.         fprintf(stdout,"     3. Profile Alignments\n");
  1167.         fprintf(stdout,"     4. Phylogenetic trees\n");
  1168.         fprintf(stdout,"\n");
  1169.         fprintf(stdout,"     S. Execute a system command\n");
  1170.         fprintf(stdout,"     H. HELP\n");
  1171.         fprintf(stdout,"     X. EXIT (leave program)\n\n\n");
  1172.         
  1173.         getstr("Your choice",lin1);
  1174.  
  1175.         switch(toupper(*lin1)) {
  1176.             case '1': seq_input();
  1177.                 break;
  1178.             case '2': multiple_align_menu();
  1179.                 break;
  1180.             case '3': profile_align_menu();
  1181.                 break;
  1182.             case '4': phylogenetic_tree_menu();
  1183.                 break;
  1184.             case 'S': do_system();
  1185.                 break;
  1186.             case '?':
  1187.             case 'H': get_help('1');
  1188.                 break;
  1189.             case 'Q':
  1190.             case 'X': exit(0);
  1191.                 break;
  1192.             default: fprintf(stderr,"\n\nUnrecognised Command\n\n");
  1193.                 break;
  1194.         }
  1195.     }
  1196. }
  1197.  
  1198.  
  1199.  
  1200.  
  1201.  
  1202.  
  1203.  
  1204.  
  1205.  
  1206. static void multiple_align_menu(void)
  1207. {
  1208.         void jumper();
  1209.         int catchint;
  1210.  
  1211.         catchint = signal(SIGINT, SIG_IGN) != SIG_IGN;
  1212.         if (catchint) {
  1213.                 if (setjmp(jmpbuf) != 0)
  1214.                         fprintf(stderr,"\n.. Interrupt\n");
  1215. #ifdef UNIX
  1216.                 if (signal(SIGINT,jumper) == BADSIG)
  1217.                         fprintf(stderr,"Error: signal\n");
  1218. #else
  1219.                 if (signal(SIGINT,SIG_DFL) == BADSIG)
  1220.                         fprintf(stderr,"Error: signal\n");
  1221. #endif
  1222.         }
  1223.  
  1224.  
  1225.     while(TRUE)
  1226.     {
  1227.         fprintf(stdout,"\n\n\n");
  1228.         fprintf(stdout,"****** MULTIPLE ALIGNMENT MENU ******\n");
  1229.         fprintf(stdout,"\n\n");
  1230.  
  1231.  
  1232.         fprintf(stdout,"    1.  Do complete multiple alignment now (%s)\n",
  1233.                         (!quick_pairalign) ? "Slow/Accurate" : "Fast/Approximate");
  1234.         fprintf(stdout,"    2.  Produce guide tree file only\n");
  1235.         fprintf(stdout,"    3.  Do alignment using old guide tree file\n\n");
  1236.         fprintf(stdout,"    4.  Toggle Slow/Fast pairwise alignments = %s\n\n",
  1237.                                         (!quick_pairalign) ? "SLOW" : "FAST");
  1238.         fprintf(stdout,"    5.  Pairwise alignment parameters\n");
  1239.         fprintf(stdout,"    6.  Multiple alignment parameters\n\n");
  1240.     fprintf(stdout,"    7.  Reset gaps between alignments?");
  1241.     if(reset_alignments)
  1242.         fprintf(stdout," = ON\n");
  1243.     else
  1244.         fprintf(stdout," = OFF\n");
  1245.         fprintf(stdout,"    8.  Toggle screen display          = %s\n",
  1246.                                         (!showaln) ? "OFF" : "ON");
  1247.         fprintf(stdout,"    9.  Output format options\n");
  1248.         fprintf(stdout,"\n");
  1249.  
  1250.         fprintf(stdout,"    S.  Execute a system command\n");
  1251.         fprintf(stdout,"    H.  HELP\n");
  1252.         fprintf(stdout,"    or press [RETURN] to go back to main menu\n\n\n");
  1253.  
  1254.         getstr("Your choice",lin1);
  1255.         if(*lin1 == EOS) return;
  1256.  
  1257.         switch(toupper(*lin1))
  1258.         {
  1259.         case '1': align();
  1260.             break;
  1261.         case '2': make_tree();
  1262.             break;
  1263.         case '3': get_tree();
  1264.             break;
  1265.         case '4': quick_pairalign ^= TRUE;
  1266.             break;
  1267.         case '5': pair_menu();
  1268.             break;
  1269.         case '6': multi_menu();
  1270.             break;
  1271.     case '7': reset_alignments ^= TRUE;
  1272.             break;
  1273.         case '8': showaln ^= TRUE;
  1274.         break;
  1275.         case '9': format_options_menu();
  1276.             break;
  1277.         case 'S': do_system();
  1278.             break;
  1279.         case '?':
  1280.         case 'H': get_help('2');
  1281.             break;
  1282.         case 'Q':
  1283.         case 'X': return;
  1284.  
  1285.         default: fprintf(stderr,"\n\nUnrecognised Command\n\n");
  1286.             break;
  1287.         }
  1288.     }
  1289. }
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299. static void profile_align_menu(void)
  1300. {
  1301.         void jumper();
  1302.         int catchint;
  1303.  
  1304.         catchint = signal(SIGINT, SIG_IGN) != SIG_IGN;
  1305.         if (catchint) {
  1306.                 if (setjmp(jmpbuf) != 0)
  1307.                         fprintf(stderr,"\n.. Interrupt\n");
  1308. #ifdef UNIX
  1309.                 if (signal(SIGINT,jumper) == BADSIG)
  1310.                         fprintf(stderr,"Error: signal\n");
  1311. #else
  1312.                 if (signal(SIGINT,SIG_DFL) == BADSIG)
  1313.                         fprintf(stderr,"Error: signal\n");
  1314. #endif
  1315.         }
  1316.  
  1317.  
  1318.     while(TRUE)
  1319.     {
  1320.     fprintf(stdout,"\n\n\n");
  1321.         fprintf(stdout,"****** PROFILE ALIGNMENT MENU ******\n");
  1322.         fprintf(stdout,"\n\n");
  1323.  
  1324.         fprintf(stdout,"    1.  Input 1st. profile\n");
  1325.         fprintf(stdout,"    2.  Input 2nd. profile/sequences\n\n");
  1326.         fprintf(stdout,"    3.  Align 2nd. profile to 1st. profile\n");
  1327.         fprintf(stdout,"    4.  Align sequences to 1st. profile (%s)\n\n",
  1328.                         (!quick_pairalign) ? "Slow/Accurate" : "Fast/Approximate");
  1329.         fprintf(stdout,"    5.  Toggle Slow/Fast pairwise alignments = %s\n\n",
  1330.                                         (!quick_pairalign) ? "SLOW" : "FAST");
  1331.         fprintf(stdout,"    6.  Pairwise alignment parameters\n");
  1332.         fprintf(stdout,"    7.  Multiple alignment parameters\n\n");
  1333.         fprintf(stdout,"    8.  Toggle screen display                = %s\n",
  1334.                                         (!showaln) ? "OFF" : "ON");
  1335.         fprintf(stdout,"    9.  Output format options\n");
  1336.         fprintf(stdout,"\n");
  1337.         fprintf(stdout,"    S.  Execute a system command\n");
  1338.         fprintf(stdout,"    H.  HELP\n");
  1339.         fprintf(stdout,"    or press [RETURN] to go back to main menu\n\n\n");
  1340.  
  1341.         getstr("Your choice",lin1);
  1342.         if(*lin1 == EOS) return;
  1343.  
  1344.         switch(toupper(*lin1))
  1345.         {
  1346.         case '1': profile_input(1);      /* 1 => 1st profile */
  1347.           strcpy(profile1_name, seqname);
  1348.             break;
  1349.         case '2': profile_input(2);      /* 2 => 2nd profile */
  1350.           strcpy(profile2_name, seqname);
  1351.             break;
  1352.         case '3': profile_align();       /* align the 2 alignments now */
  1353.             break;
  1354.         case '4': new_sequence_align();  /* align new sequences to profile 1 */
  1355.             break;
  1356.         case '5': quick_pairalign ^= TRUE;
  1357.         break;
  1358.         case '6': pair_menu();
  1359.             break;
  1360.         case '7': multi_menu();
  1361.             break;
  1362.         case '8': showaln ^= TRUE;
  1363.         break;
  1364.         case '9': format_options_menu();
  1365.             break;
  1366.         case 'S': do_system();
  1367.             break;
  1368.         case '?':
  1369.         case 'H': get_help('6');
  1370.             break;
  1371.         case 'Q':
  1372.         case 'X': return;
  1373.  
  1374.         default: fprintf(stderr,"\n\nUnrecognised Command\n\n");
  1375.             break;
  1376.         }
  1377.     }
  1378. }
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390. static void phylogenetic_tree_menu(void)
  1391. {
  1392.         void jumper();
  1393.         int catchint;
  1394.  
  1395.         catchint = signal(SIGINT, SIG_IGN) != SIG_IGN;
  1396.         if (catchint) {
  1397.                 if (setjmp(jmpbuf) != 0)
  1398.                         fprintf(stderr,"\n.. Interrupt\n");
  1399. #ifdef UNIX
  1400.                 if (signal(SIGINT,jumper) == BADSIG)
  1401.                         fprintf(stderr,"Error: signal\n");
  1402. #else
  1403.                 if (signal(SIGINT,SIG_DFL) == BADSIG)
  1404.                         fprintf(stderr,"Error: signal\n");
  1405. #endif
  1406.         }
  1407.  
  1408.  
  1409.     while(TRUE)
  1410.     {
  1411.         fprintf(stdout,"\n\n\n");
  1412.         fprintf(stdout,"****** PHYLOGENETIC TREE MENU ******\n");
  1413.         fprintf(stdout,"\n\n");
  1414.  
  1415.         fprintf(stdout,"    1.  Input an alignment\n");
  1416.         fprintf(stdout,"    2.  Exclude positions with gaps?        ");
  1417.     if(tossgaps)
  1418.         fprintf(stdout,"= ON\n");
  1419.     else
  1420.         fprintf(stdout,"= OFF\n");
  1421.         fprintf(stdout,"    3.  Correct for multiple substitutions? ");
  1422.     if(kimura)
  1423.         fprintf(stdout,"= ON\n");
  1424.     else
  1425.         fprintf(stdout,"= OFF\n");
  1426.         fprintf(stdout,"    4.  Draw tree now\n");
  1427.         fprintf(stdout,"    5.  Bootstrap tree\n");
  1428.     fprintf(stdout,"    6.  Output format options\n");
  1429.         fprintf(stdout,"\n");
  1430.         fprintf(stdout,"    S.  Execute a system command\n");
  1431.         fprintf(stdout,"    H.  HELP\n");
  1432.         fprintf(stdout,"    or press [RETURN] to go back to main menu\n\n\n");
  1433.  
  1434.         getstr("Your choice",lin1);
  1435.         if(*lin1 == EOS) return;
  1436.  
  1437.         switch(toupper(*lin1))
  1438.         {
  1439.                 case '1': seq_input();
  1440.                     break;
  1441.             case '2': tossgaps ^= TRUE;
  1442.                     break;
  1443.               case '3': kimura ^= TRUE;;
  1444.                     break;
  1445.             case '4': phylogenetic_tree();
  1446.                     break;
  1447.             case '5': bootstrap_tree();
  1448.                     break;
  1449.         case '6': tree_format_options_menu();
  1450.             break;
  1451.             case 'S': do_system();
  1452.                     break;
  1453.                 case '?':
  1454.             case 'H': get_help('7');
  1455.                     break;
  1456.                 case 'Q':
  1457.             case 'X': return;
  1458.  
  1459.             default: fprintf(stderr,"\n\nUnrecognised Command\n\n");
  1460.                 break;
  1461.         }
  1462.     }
  1463. }
  1464.  
  1465.  
  1466.  
  1467.  
  1468.  
  1469.  
  1470. static void tree_format_options_menu(void)      /* format of tree output */
  1471. {    
  1472.         void jumper();
  1473.         int catchint;
  1474.     char path[FILENAMELEN+1];
  1475.  
  1476.         catchint = signal(SIGINT, SIG_IGN) != SIG_IGN;
  1477.         if (catchint) {
  1478.                 if (setjmp(jmpbuf) != 0)
  1479.                         fprintf(stderr,"\n.. Interrupt\n");
  1480. #ifdef UNIX
  1481.                 if (signal(SIGINT,jumper) == BADSIG)
  1482.                         fprintf(stderr,"Error: signal\n");
  1483. #else
  1484.                 if (signal(SIGINT,SIG_DFL) == BADSIG)
  1485.                         fprintf(stderr,"Error: signal\n");
  1486. #endif
  1487.         }
  1488.  
  1489.  
  1490.     while(TRUE) {
  1491.     fprintf(stdout,"\n\n\n");
  1492.     fprintf(stdout," ****** Format of Phylogenetic Tree Output ******\n");
  1493.     fprintf(stdout,"\n\n");
  1494.     fprintf(stdout,"     1. Toggle CLUSTAL format tree output    =  %s\n",
  1495.                     (!output_tree_clustal)  ? "OFF" : "ON");
  1496.     fprintf(stdout,"     2. Toggle Phylip format tree output     =  %s\n",
  1497.                     (!output_tree_phylip)   ? "OFF" : "ON");
  1498.     fprintf(stdout,"     3. Toggle Phylip distance matrix output =  %s\n\n",
  1499.                     (!output_tree_distances)? "OFF" : "ON");
  1500.     fprintf(stdout,"\n");
  1501.     fprintf(stdout,"     H. HELP\n\n\n");    
  1502.     
  1503.         getstr("Enter number (or [RETURN] to exit)",lin2);
  1504.         if(*lin2 == EOS) return;
  1505.         
  1506.         switch(toupper(*lin2)) {
  1507.             case '1':
  1508.                 output_tree_clustal   ^= TRUE;
  1509.                 break;
  1510.             case '2':
  1511.                           output_tree_phylip    ^= TRUE;
  1512.                   break;
  1513.             case '3':
  1514.                           output_tree_distances ^= TRUE;
  1515.                   break;
  1516.             case '?':
  1517.             case 'H':
  1518.                 get_help('0');
  1519.                 break;
  1520.             default:
  1521.                 fprintf(stderr,"\n\nUnrecognised Command\n\n");
  1522.                 break;
  1523.         }
  1524.     }
  1525. }
  1526.  
  1527.  
  1528. static void format_options_menu(void)      /* format of alignment output */
  1529. {    
  1530.     int i,length = 0;
  1531.     char path[FILENAMELEN+1];
  1532.         void jumper();
  1533.         int catchint;
  1534.  
  1535.         catchint = signal(SIGINT, SIG_IGN) != SIG_IGN;
  1536.         if (catchint) {
  1537.                 if (setjmp(jmpbuf) != 0)
  1538.                         fprintf(stderr,"\n.. Interrupt\n");
  1539. #ifdef UNIX
  1540.                 if (signal(SIGINT,jumper) == BADSIG)
  1541.                         fprintf(stderr,"Error: signal\n");
  1542. #else
  1543.                 if (signal(SIGINT,SIG_DFL) == BADSIG)
  1544.                         fprintf(stderr,"Error: signal\n");
  1545. #endif
  1546.         }
  1547.  
  1548.  
  1549.     while(TRUE) {
  1550.     fprintf(stdout,"\n\n\n");
  1551.     fprintf(stdout," ********* Format of Alignment Output *********\n");
  1552.     fprintf(stdout,"\n\n");
  1553.     fprintf(stdout,"     1. Toggle CLUSTAL format output   =  %s\n",
  1554.                     (!output_clustal) ? "OFF" : "ON");
  1555.     fprintf(stdout,"     2. Toggle NBRF/PIR format output  =  %s\n",
  1556.                     (!output_nbrf) ? "OFF" : "ON");
  1557.     fprintf(stdout,"     3. Toggle GCG/MSF format output   =  %s\n",
  1558.                     (!output_gcg) ? "OFF" : "ON");
  1559.     fprintf(stdout,"     4. Toggle PHYLIP format output    =  %s\n",
  1560.                     (!output_phylip) ? "OFF" : "ON");
  1561.     fprintf(stdout,"     5. Toggle GDE format output       =  %s\n\n",
  1562.                     (!output_gde) ? "OFF" : "ON");
  1563.     fprintf(stdout,"     6. Toggle GDE output case         =  %s\n",
  1564.                     (!lowercase) ? "UPPER" : "LOWER");
  1565.     fprintf(stdout,"     7. Toggle output order            =  %s\n\n",
  1566.                     (output_order==0) ? "INPUT FILE" : "ALIGNED");
  1567.     fprintf(stdout,"     8. Create alignment output file(s) now?\n\n");
  1568.         fprintf(stdout,"     9. Toggle parameter output        = %s\n",
  1569.                                         (!save_parameters) ? "OFF" : "ON");
  1570.     fprintf(stdout,"\n");
  1571.     fprintf(stdout,"     H. HELP\n\n\n");    
  1572.     
  1573.         getstr("Enter number (or [RETURN] to exit)",lin2);
  1574.         if(*lin2 == EOS) return;
  1575.         
  1576.         switch(toupper(*lin2)) {
  1577.             case '1':
  1578.                 output_clustal ^= TRUE;
  1579.                 break;
  1580.             case '2':
  1581.                           output_nbrf ^= TRUE;
  1582.                   break;
  1583.             case '3':
  1584.                           output_gcg ^= TRUE;
  1585.                   break;
  1586.             case '4':
  1587.                           output_phylip ^= TRUE;
  1588.                   break;
  1589.             case '5':
  1590.                           output_gde ^= TRUE;
  1591.                   break;
  1592.             case '6':
  1593.                           lowercase ^= TRUE;
  1594.                   break;
  1595.             case '7':
  1596.                                 if (output_order == INPUT) output_order = ALIGNED;
  1597.                           else output_order = INPUT;
  1598.                   break;
  1599.             case '8':        /* DES */
  1600.                 if(empty) break;
  1601.                 get_path(seqname,path);
  1602.                 if(!open_alignment_output(path)) break;
  1603.                 for (i=1;i<=nseqs;i++)
  1604.                     if (length < seqlen_array[i]) 
  1605.                         length = seqlen_array[i];
  1606. /* DES DEBUG
  1607.     fprintf(stdout,"\n\nLength = %d",(pint)length);
  1608. */
  1609.                 create_alignment_output(length);
  1610.                 break;
  1611.                 case '9': save_parameters ^= TRUE;
  1612.                     break;
  1613.             case '?':
  1614.             case 'H':
  1615.                 get_help('5');
  1616.                 break;
  1617.             default:
  1618.                 fprintf(stderr,"\n\nUnrecognised Command\n\n");
  1619.                 break;
  1620.         }
  1621.     }
  1622. }
  1623.  
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635. static void pair_menu(void)
  1636. {
  1637.         void jumper();
  1638.         int catchint;
  1639.  
  1640.         catchint = signal(SIGINT, SIG_IGN) != SIG_IGN;
  1641.         if (catchint) {
  1642.                 if (setjmp(jmpbuf) != 0)
  1643.                         fprintf(stderr,"\n.. Interrupt\n");
  1644. #ifdef UNIX
  1645.                 if (signal(SIGINT,jumper) == BADSIG)
  1646.                         fprintf(stderr,"Error: signal\n");
  1647. #else
  1648.                 if (signal(SIGINT,SIG_DFL) == BADSIG)
  1649.                         fprintf(stderr,"Error: signal\n");
  1650. #endif
  1651.         }
  1652.  
  1653.  
  1654.         if(dnaflag) {
  1655.                 pw_go_penalty     = dna_pw_go_penalty;
  1656.                 pw_ge_penalty     = dna_pw_ge_penalty;
  1657.                 ktup       = dna_ktup;
  1658.                 window     = dna_window;
  1659.                 signif     = dna_signif;
  1660.                 wind_gap   = dna_wind_gap;
  1661.  
  1662.         }
  1663.         else {
  1664.                 pw_go_penalty     = prot_pw_go_penalty;
  1665.                 pw_ge_penalty     = prot_pw_ge_penalty;
  1666.                 ktup       = prot_ktup;
  1667.                 window     = prot_window;
  1668.                 signif     = prot_signif;
  1669.                 wind_gap   = prot_wind_gap;
  1670.  
  1671.         }
  1672.  
  1673.     while(TRUE) {
  1674.     
  1675.         fprintf(stdout,"\n\n\n");
  1676.         fprintf(stdout," ********* PAIRWISE ALIGNMENT PARAMETERS *********\n");
  1677.         fprintf(stdout,"\n\n");
  1678.  
  1679.         fprintf(stdout,"     Slow/Accurate alignments:\n\n");
  1680.  
  1681.         fprintf(stdout,"     1. Gap Open Penalty       :%4.2f\n",pw_go_penalty);
  1682.         fprintf(stdout,"     2. Gap Extension Penalty  :%4.2f\n",pw_ge_penalty);
  1683.         fprintf(stdout,"     3. Protein weight matrix  :%s\n\n" ,
  1684.                                         pw_matrix_txt[pw_matnum-1]);
  1685.  
  1686.         fprintf(stdout,"     Fast/Approximate alignments:\n\n");
  1687.  
  1688.         fprintf(stdout,"     4. Gap penalty            :%d\n",(pint)wind_gap);
  1689.         fprintf(stdout,"     5. K-tuple (word) size    :%d\n",(pint)ktup);
  1690.         fprintf(stdout,"     6. No. of top diagonals   :%d\n",(pint)signif);
  1691.         fprintf(stdout,"     7. Window size            :%d\n\n",(pint)window);
  1692.  
  1693.                 fprintf(stdout,"     8. Toggle Slow/Fast pairwise alignments ");
  1694.                 if(quick_pairalign)
  1695.                       fprintf(stdout,"= FAST\n\n");
  1696.                 else
  1697.                       fprintf(stdout,"= SLOW\n\n");
  1698.  
  1699.  
  1700.         fprintf(stdout,"     H. HELP\n\n\n");
  1701.         
  1702.         getstr("Enter number (or [RETURN] to exit)",lin2);
  1703.         if( *lin2 == EOS) {
  1704.                         if(dnaflag) {
  1705.                                 dna_pw_go_penalty     = pw_go_penalty;
  1706.                                 dna_pw_ge_penalty     = pw_ge_penalty;
  1707.                         dna_ktup       = ktup;
  1708.                         dna_window     = window;
  1709.                         dna_signif     = signif;
  1710.                         dna_wind_gap   = wind_gap;
  1711.  
  1712.                         }
  1713.                         else {
  1714.                                 prot_pw_go_penalty     = pw_go_penalty;
  1715.                                 prot_pw_ge_penalty     = pw_ge_penalty;
  1716.                         prot_ktup       = ktup;
  1717.                         prot_window     = window;
  1718.                         prot_signif     = signif;
  1719.                         prot_wind_gap   = wind_gap;
  1720.  
  1721.                         }
  1722.  
  1723.             return;
  1724.         }
  1725.         
  1726.         switch(toupper(*lin2)) {
  1727.             case '1':
  1728.                 fprintf(stdout,"Gap Open Penalty Currently: %4.2f\n",pw_go_penalty);
  1729.                 pw_go_penalty=(float)getreal("Enter number",(double)0.0,(double)100.0,(double)pw_go_penalty);
  1730.                 break;
  1731.             case '2':
  1732.                 fprintf(stdout,"Gap Extension Penalty Currently: %4.2f\n",pw_ge_penalty);
  1733.                 pw_ge_penalty=(float)getreal("Enter number",(double)0.0,(double)10.0,(double)pw_ge_penalty);
  1734.                 break;
  1735.                         case '3':
  1736.                                 pw_matnum = read_matrix(pw_matrix_txt,pw_mtrxname,pw_matnum,pw_usermat,pw_aa_xref);
  1737.                                 break;
  1738.             case '4':
  1739.                                 fprintf(stdout,"Gap Penalty Currently: %d\n",(pint)wind_gap);
  1740.                                 wind_gap=getint("Enter number",1,500,wind_gap);
  1741.                 break;
  1742.             case '5':
  1743.                                 fprintf(stdout,"K-tuple Currently: %d\n",(pint)ktup);
  1744.                                 if(dnaflag)
  1745.                                      ktup=getint("Enter number",1,4,ktup);
  1746.                                 else
  1747.                                      ktup=getint("Enter number",1,2,ktup);                                     
  1748.                 break;
  1749.             case '6':
  1750.                                 fprintf(stdout,"Top diagonals Currently: %d\n",(pint)signif);
  1751.                                 signif=getint("Enter number",1,50,signif);
  1752.                 break;
  1753.             case '7':
  1754.                                 fprintf(stdout,"Window size Currently: %d\n",(pint)window);
  1755.                                 window=getint("Enter number",1,50,window);
  1756.                 break;
  1757.                         case '8': quick_pairalign ^= TRUE;
  1758.                                 break;
  1759.             case '?':
  1760.             case 'H':
  1761.                 get_help('3');
  1762.                 break;
  1763.             default:
  1764.                 fprintf(stderr,"\n\nUnrecognised Command\n\n");
  1765.                 break;
  1766.         }
  1767.     }
  1768. }
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774. static void multi_menu(void)
  1775. {
  1776.     char c;
  1777.     int i;
  1778.         void jumper();
  1779.         int catchint;
  1780.  
  1781.         catchint = signal(SIGINT, SIG_IGN) != SIG_IGN;
  1782.         if (catchint) {
  1783.                 if (setjmp(jmpbuf) != 0)
  1784.                         fprintf(stderr,"\n.. Interrupt\n");
  1785. #ifdef UNIX
  1786.                 if (signal(SIGINT,jumper) == BADSIG)
  1787.                         fprintf(stderr,"Error: signal\n");
  1788. #else
  1789.                 if (signal(SIGINT,SIG_DFL) == BADSIG)
  1790.                         fprintf(stderr,"Error: signal\n");
  1791. #endif
  1792.         }
  1793.  
  1794.  
  1795.     if(dnaflag) {
  1796.         gap_open   = dna_gap_open;
  1797.         gap_extend = dna_gap_extend;
  1798.     }
  1799.     else {
  1800.         gap_open   = prot_gap_open;
  1801.         gap_extend = prot_gap_extend;
  1802.     }
  1803.  
  1804.     while(TRUE) {
  1805.                 lin3 = is_weight ? "Weighted" :"Unweighted";
  1806.  
  1807.         fprintf(stdout,"\n\n\n");
  1808.         fprintf(stdout," ********* MULTIPLE ALIGNMENT PARAMETERS *********\n");
  1809.         fprintf(stdout,"\n\n");
  1810.         
  1811.         fprintf(stdout,"     1. Gap Opening Penalty              :%4.2f\n",gap_open);
  1812.         fprintf(stdout,"     2. Gap Extension Penalty            :%4.2f\n",gap_extend);
  1813.  
  1814.         fprintf(stdout,"     3. Delay divergent sequences        :%d %%\n\n",(pint)divergence_cutoff);
  1815.  
  1816.                 fprintf(stdout,"     4. Toggle Transitions (DNA)     :%s\n\n",lin3);
  1817.                 fprintf(stdout,"     5. Protein weight matrix            :%s\n"
  1818.                                         ,matrix_txt[matnum-1]);
  1819.         fprintf(stdout,"     6. Use negative matrix              :%s\n",(!neg_matrix) ? "OFF" : "ON");
  1820.                 fprintf(stdout,"     7. Protein Gap Parameters\n\n");
  1821.         fprintf(stdout,"     H. HELP\n\n\n");        
  1822.  
  1823.         getstr("Enter number (or [RETURN] to exit)",lin2);
  1824.  
  1825.         if(*lin2 == EOS) {
  1826.             if(dnaflag) {
  1827.                 dna_gap_open    = gap_open;
  1828.                 dna_gap_extend  = gap_extend;
  1829.             }
  1830.             else {
  1831.                 prot_gap_open   = gap_open;
  1832.                 prot_gap_extend = gap_extend;
  1833.             }
  1834.             return;
  1835.         }
  1836.         
  1837.         switch(toupper(*lin2)) {
  1838.             case '1':
  1839.             fprintf(stdout,"Gap Opening Penalty Currently: %4.2f\n",gap_open);
  1840.                 gap_open=(float)getreal("Enter number",(double)0.0,(double)100.0,(double)gap_open);
  1841.                 break;
  1842.             case '2':
  1843.                 fprintf(stdout,"Gap Extension Penalty Currently: %4.2f\n",gap_extend);
  1844.                 gap_extend=(float)getreal("Enter number",(double)0.0,(double)10.0,(double)gap_extend);
  1845.                 break;
  1846.             case '3':
  1847.                 fprintf(stdout,"Min Identity Currently: %d\n",(pint)divergence_cutoff);
  1848.                 divergence_cutoff=getint("Enter number",0,100,divergence_cutoff);
  1849.                 break;
  1850.                         case '4':
  1851.                                 is_weight ^= TRUE;
  1852.                                 break;
  1853.             case '5':
  1854.                                 matnum = read_matrix(matrix_txt,mtrxname,matnum,usermat,aa_xref);
  1855.                 break;
  1856.             case '6':
  1857.                 neg_matrix ^= TRUE;
  1858.                 break;
  1859.             case '7':
  1860.                                 gap_penalties_menu();
  1861.                 break;
  1862.             case '?':
  1863.             case 'H':
  1864.                 get_help('4');
  1865.                 break;
  1866.             default:
  1867.                 fprintf(stderr,"\n\nUnrecognised Command\n\n");
  1868.                 break;
  1869.         }
  1870.     }
  1871. }
  1872.  
  1873.  
  1874.  
  1875.  
  1876.  
  1877.  
  1878. static void gap_penalties_menu(void)
  1879. {
  1880.     char c;
  1881.     int i;
  1882.         void jumper();
  1883.         int catchint;
  1884.  
  1885.         catchint = signal(SIGINT, SIG_IGN) != SIG_IGN;
  1886.         if (catchint) {
  1887.                 if (setjmp(jmpbuf) != 0)
  1888.                         fprintf(stderr,"\n.. Interrupt\n");
  1889. #ifdef UNIX
  1890.                 if (signal(SIGINT,jumper) == BADSIG)
  1891.                         fprintf(stderr,"Error: signal\n");
  1892. #else
  1893.                 if (signal(SIGINT,SIG_DFL) == BADSIG)
  1894.                         fprintf(stderr,"Error: signal\n");
  1895. #endif
  1896.         }
  1897.  
  1898.  
  1899.     while(TRUE) {
  1900.  
  1901.         fprintf(stdout,"\n\n\n");
  1902.         fprintf(stdout," ********* PROTEIN GAP PARAMETERS *********\n");
  1903.         fprintf(stdout,"\n\n\n");
  1904.  
  1905.         fprintf(stdout,"     1. Toggle Residue-Specific Penalties :%s\n\n",(no_pref_penalties) ? "OFF" : "ON");
  1906.         fprintf(stdout,"     2. Toggle Hydrophilic Penalties      :%s\n",(no_hyd_penalties) ? "OFF" : "ON");
  1907.         fprintf(stdout,"     3. Hydrophilic Residues              :%s\n\n"
  1908.                     ,hyd_residues);
  1909.         fprintf(stdout,"     4. Gap Separation Distance           :%d\n",(pint)gap_dist);
  1910.         fprintf(stdout,"     5. Toggle End Gap Separation         :%s\n\n",(!use_endgaps) ? "OFF" : "ON");
  1911.         fprintf(stdout,"     H. HELP\n\n\n");        
  1912.  
  1913.         getstr("Enter number (or [RETURN] to exit)",lin2);
  1914.  
  1915.         if(*lin2 == EOS) return;
  1916.         
  1917.         switch(toupper(*lin2)) {
  1918.             case '1':
  1919.                 no_pref_penalties ^= TRUE;
  1920.                 break;
  1921.             case '2':
  1922.                 no_hyd_penalties ^= TRUE;
  1923.                 break;
  1924.             case '3':
  1925.                 fprintf(stdout,"Hydrophilic Residues Currently: %s\n",hyd_residues);
  1926.  
  1927.                 getstr("Enter residues (or [RETURN] to quit)",lin1);
  1928.                                 if (*lin1 != EOS) {
  1929.                                         for (i=0;i<strlen(hyd_residues) && i<26;i++) {
  1930.                                         c = lin1[i];
  1931.                                         if (isalpha(c))
  1932.                                                 hyd_residues[i] = (char)toupper(c);
  1933.                                         else
  1934.                                                 break;
  1935.                                         }
  1936.                                         hyd_residues[i] = EOS;
  1937.                                 }
  1938.                                 break;
  1939.             case '4':
  1940.                 fprintf(stdout,"Gap Separation Distance Currently: %d\n",(pint)gap_dist);
  1941.                 gap_dist=getint("Enter number",0,100,gap_dist);
  1942.                 break;
  1943.             case '5':
  1944.                 use_endgaps ^= TRUE;
  1945.                 break;
  1946.             case '?':
  1947.             case 'H':
  1948.                 get_help('A');
  1949.                 break;
  1950.             default:
  1951.                 fprintf(stderr,"\n\nUnrecognised Command\n\n");
  1952.                 break;
  1953.         }
  1954.     }
  1955. }
  1956.  
  1957.  
  1958.  
  1959.  
  1960. static int read_matrix(char **mattxt, char *matnam, int matn, int *mat, int *xref)
  1961. {       static char userfile[FILENAMELEN+1];
  1962.  
  1963.         while(TRUE)
  1964.         {
  1965.                 fprintf(stdout,"\n\n\n");
  1966.                 fprintf(stdout," ********* PROTEIN WEIGHT MATRIX MENU *********\n");
  1967.                 fprintf(stdout,"\n\n");
  1968.  
  1969.  
  1970.                 fprintf(stdout,"     1. %s\n",mattxt[0]);
  1971.                 fprintf(stdout,"     2. %s\n",mattxt[1]);
  1972.                 fprintf(stdout,"     3. %s\n",mattxt[2]);
  1973.                 fprintf(stdout,"     4. %s\n\n",mattxt[3]);
  1974.                 fprintf(stdout,"     H. HELP\n\n");
  1975.                 fprintf(stdout,
  1976. "     -- Current matrix is the %s ",mattxt[matn-1]);
  1977.                 if(matn == 5) fprintf(stdout,"(file = %s)",userfile);
  1978.                 fprintf(stdout,"--\n");
  1979.  
  1980.  
  1981.                 getstr("\n\nEnter number (or [RETURN] to exit)",lin2);
  1982.                 if(*lin2 == EOS) return(matn);
  1983.  
  1984.                 switch(toupper(*lin2))  {
  1985.                         case '1':
  1986.                                 strcpy(matnam,"blosum");
  1987.                                 matn=1;
  1988.                                 break;
  1989.                         case '2':
  1990.                                 strcpy(matnam,"pam");
  1991.                                 matn=2;
  1992.                                 break;
  1993.                         case '3':
  1994.                                 strcpy(matnam,"id");
  1995.                                 matn=3;
  1996.                                 break;
  1997.                         case '4':
  1998.                                 if(user_mat(userfile, mat, xref))
  1999.                                   {
  2000.                                      strcpy(matnam,userfile);
  2001.                                      matn=4;
  2002.                                   }
  2003.                                 break;
  2004.                         case '?':
  2005.                         case 'H':
  2006.                                 get_help('8');
  2007.                                 break;
  2008.                         default:
  2009.                                 fprintf(stderr,"\n\nUnrecognised Command\n\n");
  2010.                                 break;
  2011.                 }
  2012.         }
  2013. }
  2014.  
  2015. static Boolean user_mat(char *str, int *mat, int *xref)
  2016. {
  2017.         int i,j,nv,pos,idx,val;
  2018.         int maxres;
  2019.  
  2020.         FILE *infile;
  2021.  
  2022.         if(usemenu)
  2023.                 getstr("Enter name of the matrix file",lin2);
  2024.         else
  2025.                 strcpy(lin2,str);
  2026.  
  2027.         if(*lin2 == EOS) return FALSE;
  2028.  
  2029.         if((infile=fopen(lin2,"r"))==NULL) {
  2030.                 error("Cannot find matrix file [%s]",lin2);
  2031.                 return FALSE;
  2032.         }
  2033.  
  2034.     strcpy(str, lin2);
  2035.  
  2036.     maxres = read_user_matrix(str, mat, xref);
  2037.         if (maxres <= 0) return FALSE;
  2038.  
  2039.     return TRUE;
  2040. }
  2041.  
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047. static void seq_input(void)
  2048. {
  2049.     char c;
  2050.         int i;
  2051.     
  2052.     if(usemenu) {
  2053. fprintf(stdout,"\n\nSequences should all be in 1 file.\n"); 
  2054. fprintf(stdout,"\n6 formats accepted: \n");
  2055. fprintf(stdout,
  2056. "NBRF/PIR, EMBL/SwissProt, Pearson (Fasta), GDE, Clustal, GCG/MSF.\n\n\n");
  2057. /*fprintf(stdout,
  2058. "\nGCG users should use TOPIR to convert their sequence files before use.\n\n\n");*/
  2059.     }
  2060.  
  2061.     
  2062.        nseqs = readseqs(1);        /*  1 is the first seq to be read */
  2063.        if(nseqs < 0)               /* file could not be opened */
  2064.            { 
  2065.                nseqs = 0;
  2066.                empty = TRUE;
  2067.            }
  2068.        else if(nseqs == 0)         /* no sequences */
  2069.            {
  2070.            error("No sequences in file!  Bad format?");
  2071.                empty = TRUE;
  2072.            }
  2073.        else if(nseqs == 1)
  2074.            {
  2075.                error("Only one sequence in file!");
  2076.                empty = TRUE;
  2077.                nseqs = 0;
  2078.            }
  2079.        else 
  2080.            {
  2081.         fprintf(stdout,"\nSequences assumed to be %s \n\n",
  2082.             dnaflag?"DNA":"PROTEIN");
  2083.                 for(i=1; i<=nseqs; i++) {
  2084. /* DES                         fprintf(stdout,"%s: = ",names[i]); */
  2085.                         fprintf(stdout,"Sequence %d: %-*s   %6.d %s\n",
  2086.                         (pint)i,MAXNAMES,names[i],(pint)seqlen_array[i],dnaflag?"bp":"aa");
  2087.                 }    
  2088.             if(dnaflag) {
  2089.                 gap_open   = dna_gap_open;
  2090.                 gap_extend = dna_gap_extend;
  2091.             }
  2092.             else {
  2093.                 gap_open   = prot_gap_open;
  2094.                 gap_extend = prot_gap_extend;
  2095.             }
  2096.             empty=FALSE;
  2097.                 first_seq = 1;
  2098.                 last_seq = nseqs;
  2099.        }
  2100.     
  2101. }
  2102.  
  2103.  
  2104.  
  2105.  
  2106.  
  2107.  
  2108.  
  2109. static void profile_input(int profile_no)   /* read a profile   */
  2110. {                                           /* profile_no is 1 or 2  */
  2111.     char c;
  2112.         int local_nseqs, i;
  2113.     
  2114.         if(profile_no == 2 && profile1_empty) 
  2115.            {
  2116.              error("You must read in profile number 1 first");
  2117.              return;
  2118.            }
  2119.  
  2120.  
  2121.     if(profile_no == 1)     /* for the 1st profile */
  2122.       {
  2123.        local_nseqs = readseqs(1); /* (1) means 1st seq to be read = no. 1 */
  2124.        if(local_nseqs < 0)               /* file could not be opened */
  2125.            return;
  2126.        else if(local_nseqs == 0)         /* no sequences  */
  2127.            {
  2128.            error("No sequences in file!  Bad format?");
  2129.            return;
  2130.            }
  2131.        else 
  2132.            {                 /* success; found some seqs. */
  2133.                 nseqs = profile1_nseqs = local_nseqs;
  2134.         fprintf(stdout,"\nNo. of seqs=%d\n",(pint)nseqs);
  2135.         profile1_empty=FALSE;
  2136.                 first_seq = 1;
  2137.                 last_seq = nseqs;
  2138.         profile2_empty=TRUE;
  2139.        }
  2140.       }
  2141.     else
  2142.       {                    /* first seq to be read = profile1_nseqs + 1 */
  2143.        local_nseqs = readseqs(profile1_nseqs+1); 
  2144.        if(local_nseqs < 0)               /* file could not be opened */
  2145.                profile2_empty = TRUE;
  2146.        else if(local_nseqs == 0)         /* no sequences */
  2147.            {
  2148.            error("No sequences in file!  Bad format?");
  2149.                profile2_empty = TRUE;
  2150.            }
  2151.        else 
  2152.            {
  2153.         fprintf(stdout,"\nNo. of seqs in profile=%d\n",(pint)local_nseqs);
  2154.                 nseqs = profile1_nseqs + local_nseqs;
  2155.                 fprintf(stdout,"\nTotal no. of seqs     =%d\n",(pint)nseqs);
  2156.         profile2_empty=FALSE;
  2157.         empty = FALSE;
  2158.                 first_seq = 1;
  2159.                 last_seq = nseqs;
  2160.        }
  2161.  
  2162.       }
  2163.     
  2164.     fprintf(stdout,"\nSequences assumed to be %s \n\n",
  2165.         dnaflag?"DNA":"PROTEIN");
  2166.         for(i=profile2_empty?1:profile1_nseqs+1; i<=nseqs; i++) {
  2167.                 fprintf(stdout,"Sequence %d: %-*s   %6.d %s\n",
  2168.                    (pint)i,MAXNAMES,names[i],(pint)seqlen_array[i],dnaflag?"bp":"aa");
  2169.         }    
  2170.     if(dnaflag) {
  2171.         gap_open   = dna_gap_open;
  2172.         gap_extend = dna_gap_extend;
  2173.     }
  2174.     else {
  2175.         gap_open   = prot_gap_open;
  2176.         gap_extend = prot_gap_extend;
  2177.     }
  2178. }
  2179.  
  2180.  
  2181.  
  2182.  
  2183.  
  2184.  
  2185. FILE *  open_output_file(char *prompt,      char *path, 
  2186.                 char *file_name,   char *file_extension)
  2187.  
  2188. {    static char temp[FILENAMELEN+1];
  2189.     static char local_prompt[MAXLINE];
  2190.     int useprompt = FALSE;
  2191.     FILE * file_handle;
  2192.  
  2193. /*    if (*file_name == EOS) {
  2194. */        strcpy(file_name,path);
  2195.         strcat(file_name,file_extension);
  2196. /*    }
  2197. */
  2198.     if(strcmp(file_name,seqname)==0) {
  2199.         strcpy(local_prompt,"\nError: Output file name is the same as input file.\n\nEnter new name to avoid overwriting ");
  2200.         useprompt = TRUE;
  2201.     }
  2202.     else 
  2203.         strcpy(local_prompt,prompt);
  2204.     strcat(local_prompt," [%s]: ");          
  2205.  
  2206.     if(usemenu || useprompt) {
  2207.         fprintf(stdout,local_prompt,file_name);
  2208.         gets(temp);
  2209.         if(*temp != EOS) strcpy(file_name,temp);
  2210.     }
  2211.  
  2212. #ifdef VMS
  2213.     if((file_handle=fopen(file_name,"w","rat=cr","rfm=var"))==NULL) {
  2214. #else
  2215.     if((file_handle=fopen(file_name,"w"))==NULL) {
  2216. #endif
  2217.         error("Cannot open output file [%s]",file_name);
  2218.         return NULL;
  2219.     }
  2220.     return file_handle;
  2221. }
  2222.  
  2223.  
  2224.  
  2225. FILE *  open_explicit_file(char *file_name)
  2226.     FILE * file_handle;
  2227.  
  2228.     if (*file_name == EOS) {
  2229.         error("Bad output file [%s]",file_name);
  2230.         return NULL;
  2231.     }
  2232. #ifdef VMS
  2233.     if((file_handle=fopen(file_name,"w","rat=cr","rfm=var"))==NULL) {
  2234. #else
  2235.     if((file_handle=fopen(file_name,"w"))==NULL) {
  2236. #endif
  2237.         error("Cannot open output file [%s]",file_name);
  2238.         return NULL;
  2239.     }
  2240.     return file_handle;
  2241. }
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.  
  2249.  
  2250.  
  2251. static void align(void)
  2252.     FILE *tree;
  2253.     char path[FILENAMELEN+1],temp[FILENAMELEN+1];
  2254.     int i,count,length = 0;
  2255.     
  2256.     if(empty && usemenu) {
  2257.         error("No sequences in memory. Load sequences first.");
  2258.         return;
  2259.     }
  2260.  
  2261.         get_path(seqname,path);
  2262. /* DES DEBUG 
  2263.     fprintf(stdout,"\n\n Seqname = %s  \n Path = %s \n\n",seqname,path);
  2264. */
  2265.         if(!open_alignment_output(path)) return;
  2266.  
  2267.     if (nseqs > 3)
  2268.     if (explicit_treefile) {
  2269.         if((phylip_phy_tree_file = open_explicit_file(
  2270.         phylip_phy_tree_name))==NULL) return;
  2271.     }
  2272.     else {
  2273.             if((phylip_phy_tree_file = open_output_file(
  2274.                 "\nEnter name for GUIDE TREE          file  ",path,
  2275.                 phylip_phy_tree_name,"dnd")) == NULL) return;
  2276.     }
  2277.  
  2278.     if (save_parameters) create_parameter_output();
  2279.  
  2280.     if(reset_alignments) reset();
  2281.  
  2282.         fprintf(stdout,"\nStart of Pairwise alignments\n");
  2283.         fprintf(stdout,"Aligning...\n");
  2284.         if(dnaflag) {
  2285.                 gap_open   = dna_gap_open;
  2286.                 gap_extend = dna_gap_extend;
  2287.                 pw_go_penalty  = dna_pw_go_penalty;
  2288.                 pw_ge_penalty  = dna_pw_ge_penalty;
  2289.                 ktup       = dna_ktup;
  2290.                 window     = dna_window;
  2291.                 signif     = dna_signif;
  2292.                 wind_gap   = dna_wind_gap;
  2293.  
  2294.         }
  2295.         else {
  2296.                 gap_open   = prot_gap_open;
  2297.                 gap_extend = prot_gap_extend;
  2298.                 pw_go_penalty  = prot_pw_go_penalty;
  2299.                 pw_ge_penalty  = prot_pw_ge_penalty;
  2300.                 ktup       = prot_ktup;
  2301.                 window     = prot_window;
  2302.                 signif     = prot_signif;
  2303.                 wind_gap   = prot_wind_gap;
  2304.  
  2305.         }
  2306.  
  2307.         if (quick_pairalign)
  2308.            show_pair();
  2309.         else
  2310.            pairalign(0,nseqs,0,nseqs);
  2311.  
  2312.     if (nseqs > 3) guide_tree();
  2313.     
  2314.     count = malign(0);
  2315.     
  2316.     if (count <= 0) return;
  2317.  
  2318.     fprintf(stdout,"\n\n\n");
  2319.         for (i=1;i<=nseqs;i++)
  2320.            if (length < seqlen_array[i]) length = seqlen_array[i];
  2321.     fprintf(stdout,"Consensus length = %d\n",(pint)length);
  2322.     
  2323.     create_alignment_output(length);
  2324.         if (showaln && usemenu) show_aln();
  2325. }
  2326.  
  2327.  
  2328.  
  2329.  
  2330.  
  2331. static void new_sequence_align(void)
  2332.     FILE *tree;
  2333.     char path[FILENAMELEN+1],temp[FILENAMELEN+1];
  2334.         char line[MAXLINE];
  2335.     int i,j,count,status,length = 0;
  2336.     Boolean tclustal, tdistance, tphylip;
  2337.     double dscore;
  2338.     
  2339.     if(profile1_empty && usemenu) {
  2340.         error("No profile in memory. Input 1st profile first.");
  2341.         return;
  2342.     }
  2343.  
  2344.     if(profile2_empty && usemenu) {
  2345.         error("No sequences in memory. Input sequences first.");
  2346.         return;
  2347.     }
  2348.  
  2349.         get_path(profile2_name,path);
  2350.  
  2351.         if(!open_alignment_output(path)) return;
  2352.  
  2353.     new_seq = profile1_nseqs+1;
  2354.  
  2355. /* get the phylogenetic tree from *.dnd */
  2356. /*
  2357.     if (nseqs > 3) {
  2358.             get_path(profile1_name,path);
  2359.                 strcpy(phylip_phy_tree_name,path);
  2360.                 strcat(phylip_phy_tree_name,"dnd");
  2361.  
  2362.         tdistance = output_tree_distances;
  2363.         tclustal = output_tree_clustal;
  2364.         tphylip = output_tree_phylip;
  2365.         output_tree_distances = output_tree_clustal = FALSE;
  2366.         output_tree_phylip = TRUE;
  2367.  
  2368.         phylogenetic_tree();
  2369.         output_tree_distances = tdistance;
  2370.         output_tree_clustal = tclustal;
  2371.         output_tree_phylip = tphylip;
  2372.         status = read_tree(phylip_phy_tree_name, 0, nseqs);
  2373.           if (status == 0) return;
  2374.     }
  2375. */
  2376.  
  2377.     for (i=1;i<=new_seq;i++) {
  2378.              for (j=i+1;j<=new_seq;j++) {
  2379.                    dscore = countid(i,j);
  2380.                    tmat[i][j] = (100.0 - dscore)/100.0;
  2381.                    tmat[j][i] = tmat[i][j];
  2382.              }
  2383.        }
  2384.  
  2385.  
  2386.  
  2387. /* calculate tmat matrix as distance matrix */
  2388.  
  2389. /*
  2390.     status = calc_distances(new_seq-1);
  2391.     if (status == 0) return;
  2392.  
  2393.     if (nseqs > 3) {
  2394.         clear_tree(NULL);
  2395.     }
  2396. */
  2397.  
  2398. /* open the new tree file */
  2399.  
  2400.     if (nseqs > 3)
  2401.     if (explicit_treefile) {
  2402.         if((phylip_phy_tree_file = open_explicit_file(
  2403.         phylip_phy_tree_name))==NULL) return;
  2404.     }
  2405.     else {
  2406.             get_path(profile2_name,path);
  2407.                 strcpy(phylip_phy_tree_name,path);
  2408.                 strcat(phylip_phy_tree_name,"dnd");
  2409.             if((phylip_phy_tree_file = open_output_file(
  2410.                 "\nEnter name for new GUIDE TREE          file  ",path,
  2411.                 phylip_phy_tree_name,"dnd")) == NULL) return;
  2412.     }
  2413.  
  2414.     if (save_parameters) create_parameter_output();
  2415.  
  2416.     if(reset_alignments) reset();
  2417.  
  2418.         fprintf(stdout,"\nStart of Pairwise alignments\n");
  2419.         fprintf(stdout,"Aligning...\n");
  2420.         if(dnaflag) {
  2421.                 gap_open   = dna_gap_open;
  2422.                 gap_extend = dna_gap_extend;
  2423.                 pw_go_penalty  = dna_pw_go_penalty;
  2424.                 pw_ge_penalty  = dna_pw_ge_penalty;
  2425.                 ktup       = dna_ktup;
  2426.                 window     = dna_window;
  2427.                 signif     = dna_signif;
  2428.                 wind_gap   = dna_wind_gap;
  2429.  
  2430.         }
  2431.         else {
  2432.                 gap_open   = prot_gap_open;
  2433.                 gap_extend = prot_gap_extend;
  2434.                 pw_go_penalty  = prot_pw_go_penalty;
  2435.                 pw_ge_penalty  = prot_pw_ge_penalty;
  2436.                 ktup       = prot_ktup;
  2437.                 window     = prot_window;
  2438.                 signif     = prot_signif;
  2439.                 wind_gap   = prot_wind_gap;
  2440.  
  2441.         }
  2442.  
  2443.         if (quick_pairalign)
  2444.            show_pair();
  2445.         else
  2446.            pairalign(0,nseqs,new_seq-2,nseqs);
  2447.  
  2448.     if (nseqs > 3) guide_tree();
  2449.     
  2450.     count = malign(new_seq-2);
  2451.     
  2452.     if (count <= 0) return;
  2453.  
  2454.     fprintf(stdout,"\n\n\n");
  2455.         for (i=1;i<=nseqs;i++)
  2456.            if (length < seqlen_array[i]) length = seqlen_array[i];
  2457.     fprintf(stdout,"Consensus length = %d\n",(pint)length);
  2458.     
  2459.     create_alignment_output(length);
  2460.         if (showaln && usemenu) show_aln();
  2461.  
  2462. }
  2463.  
  2464.  
  2465.  
  2466.  
  2467.  
  2468.  
  2469.  
  2470.  
  2471.  
  2472. static void make_tree(void)
  2473. {
  2474.     char path[FILENAMELEN+1],temp[FILENAMELEN+1];
  2475.     
  2476.     if(empty) {
  2477.         error("No sequences in memory. Load sequences first.");
  2478.         return;
  2479.     }
  2480.  
  2481.     if(reset_alignments) reset();
  2482.  
  2483.         get_path(seqname,path);
  2484.  
  2485.     if (nseqs <= 3) {
  2486.         error("Less than 3 sequences in memory. Phylogenetic tree cannot be built.");
  2487.         return;
  2488.     }
  2489.  
  2490.     if (explicit_treefile) {
  2491.         if((phylip_phy_tree_file = open_explicit_file(
  2492.         phylip_phy_tree_name))==NULL) return;
  2493.     }
  2494.     else {
  2495.                 if((phylip_phy_tree_file = open_output_file(
  2496.                 "\nEnter name for GUIDE TREE          file  ",path,
  2497.                 phylip_phy_tree_name,"dnd")) == NULL) return;
  2498.     }
  2499.  
  2500.     if (save_parameters) create_parameter_output();
  2501.  
  2502.     fprintf(stdout,"\nStart of Pairwise alignments\n");
  2503.     fprintf(stdout,"Aligning...\n");
  2504.         if(dnaflag) {
  2505.                 gap_open   = dna_gap_open;
  2506.                 gap_extend = dna_gap_extend;
  2507.                 pw_go_penalty  = dna_pw_go_penalty;
  2508.                 pw_ge_penalty  = dna_pw_ge_penalty;
  2509.                 ktup       = dna_ktup;
  2510.                 window     = dna_window;
  2511.                 signif     = dna_signif;
  2512.                 wind_gap   = dna_wind_gap;
  2513.  
  2514.         }
  2515.         else {
  2516.                 gap_open   = prot_gap_open;
  2517.                 gap_extend = prot_gap_extend;
  2518.                 pw_go_penalty  = prot_pw_go_penalty;
  2519.                 pw_ge_penalty  = prot_pw_ge_penalty;
  2520.                 ktup       = prot_ktup;
  2521.                 window     = prot_window;
  2522.                 signif     = prot_signif;
  2523.                 wind_gap   = prot_wind_gap;
  2524.  
  2525.  
  2526.         }
  2527.    
  2528.         if (quick_pairalign)
  2529.           show_pair();
  2530.         else
  2531.           pairalign(0,nseqs,0,nseqs);
  2532.  
  2533.         if (nseqs > 3) guide_tree();
  2534.     
  2535.     if(reset_alignments) reset();
  2536.  
  2537. }
  2538.  
  2539.  
  2540.  
  2541.  
  2542.  
  2543.  
  2544.  
  2545.  
  2546.  
  2547. static void get_tree(void)
  2548. {
  2549.     char path[FILENAMELEN+1],temp[MAXLINE+1];
  2550.     int i,count,length = 0;
  2551.     
  2552.     if(empty) {
  2553.         error("No sequences in memory. Load sequences first.");
  2554.         return;
  2555.     }
  2556.  
  2557.         get_path(seqname,path);
  2558.  
  2559.     if(!open_alignment_output(path)) return;
  2560.  
  2561.     if(reset_alignments) reset();
  2562.  
  2563.         get_path(seqname,path);
  2564.  
  2565.         if (nseqs > 3) {
  2566.           
  2567.             if(usemenu) {
  2568.                    strcpy(phylip_phy_tree_name,path);
  2569.                    strcat(phylip_phy_tree_name,"dnd");
  2570.  
  2571.             fprintf(stdout,"\nEnter a name for the guide tree file [%s]: ",
  2572.                                            phylip_phy_tree_name);
  2573.                     gets(temp);
  2574.                     if(*temp != EOS)
  2575.                             strcpy(phylip_phy_tree_name,temp);
  2576.             }
  2577.  
  2578. #ifdef VMS
  2579.             if((tree=fopen(phylip_phy_tree_name,"r","rat=cr","rfm=var"))==NULL) {
  2580. #else
  2581.             if((tree=fopen(phylip_phy_tree_name,"r"))==NULL) {
  2582. #endif
  2583.                     error("Cannot open file [%s]",phylip_phy_tree_name);
  2584.                     return;
  2585.             }
  2586.     }
  2587.     else {
  2588.             fprintf(stdout,"\nStart of Pairwise alignments\n");
  2589.             fprintf(stdout,"Aligning...\n");
  2590.             if(dnaflag) {
  2591.                     gap_open   = dna_gap_open;
  2592.                     gap_extend = dna_gap_extend;
  2593.                     pw_go_penalty  = dna_pw_go_penalty;
  2594.                     pw_ge_penalty  = dna_pw_ge_penalty;
  2595.                     ktup       = dna_ktup;
  2596.                     window     = dna_window;
  2597.                     signif     = dna_signif;
  2598.                     wind_gap   = dna_wind_gap;
  2599.  
  2600.             }
  2601.             else {
  2602.                     gap_open   = prot_gap_open;
  2603.                     gap_extend = prot_gap_extend;
  2604.                     pw_go_penalty  = prot_pw_go_penalty;
  2605.                     pw_ge_penalty  = prot_pw_ge_penalty;
  2606.                     ktup       = prot_ktup;
  2607.                     window     = prot_window;
  2608.                     signif     = prot_signif;
  2609.                     wind_gap   = prot_wind_gap;
  2610.  
  2611.             }
  2612.  
  2613.                 if (quick_pairalign)
  2614.                    show_pair();
  2615.                 else
  2616.            pairalign(0,nseqs,0,nseqs);
  2617.     }
  2618.  
  2619.     if (save_parameters) create_parameter_output();
  2620.  
  2621.     count = malign(0);
  2622.     if (count <= 0) return;
  2623.  
  2624.         for (i=1;i<=nseqs;i++)
  2625.            if (length < seqlen_array[i]) length = seqlen_array[i];
  2626.     fprintf(stdout,"\n\n\n");
  2627.     fprintf(stdout,"Consensus length = %d\n",(pint)length);
  2628.  
  2629.     create_alignment_output(length);
  2630.         if (showaln && usemenu) show_aln();
  2631.  
  2632. }
  2633.  
  2634.  
  2635.  
  2636.  
  2637.  
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643. static void profile_align(void)
  2644. {
  2645.     char path[FILENAMELEN+1],temp[MAXLINE+1];
  2646.     int i,count,length = 0;
  2647.     static int sav_oc, sav_od, sav_op;
  2648.     
  2649.     if(profile2_empty) {
  2650.         error("No sequences in memory. Load sequences first.");
  2651.         return;
  2652.     }
  2653.  
  2654.     get_path(seqname,path);
  2655.     
  2656.     if(!open_alignment_output(path)) return;
  2657.  
  2658.     if(reset_alignments) reset();
  2659.  
  2660.         if (nseqs > 3)
  2661.         if((phylip_phy_tree_file = open_output_file(
  2662.                 "\nEnter a name for the GUIDE TREE     file ",path,
  2663.                 phylip_phy_tree_name,"dnd")) == NULL) return;
  2664.  
  2665.     if (save_parameters) create_parameter_output();
  2666.  
  2667.         count = palign1();
  2668.         if (count == 0) return;
  2669.  
  2670.         if (nseqs > 3) guide_tree();
  2671.  
  2672.         count = palign2();
  2673.  
  2674.     if (count == 0) return;
  2675.  
  2676.         for (i=1;i<=nseqs;i++)
  2677.            if (length < seqlen_array[i])
  2678.                length = seqlen_array[i];
  2679.     fprintf(stdout,"\n\n\n");
  2680.     fprintf(stdout,"Consensus length = %d\n",(pint)length);
  2681.  
  2682.     create_alignment_output(length);
  2683.         if (showaln && usemenu) show_aln();
  2684.  
  2685. }
  2686.  
  2687.  
  2688.  
  2689.  
  2690.  
  2691.  
  2692.  
  2693.  
  2694. static void clustal_out(FILE *clusout, int len)
  2695. {
  2696.     static char seq1[MAXLEN+1];
  2697.     char         temp[MAXLINE];
  2698.     char c;
  2699.     int val,i,ii,j,k,l,a,b;
  2700.     int chunks,ident,catident[NUMRES],lv1,pos,ptr,copt,flag;
  2701.  
  2702. /*
  2703.  stop doing this ...... opens duplicate files in VMS  DES
  2704. fclose(clusout);
  2705. if ((clusout=fopen(clustal_outname,"w")) == NULL)
  2706.   {
  2707.     fprintf(stderr,"Error opening %s\n",clustal_outfile);
  2708.     return;
  2709.   }
  2710. */
  2711.     fprintf(clusout,"CLUSTAL W(%2.1f) multiple sequence alignment\n\n\n",
  2712.                                                 revision_level);
  2713.  
  2714.     chunks = len/LINELENGTH;
  2715.     if(len % LINELENGTH != 0)
  2716.         ++chunks;
  2717.         
  2718.     for(lv1=1;lv1<=chunks;++lv1) {
  2719.         pos = ((lv1-1)*LINELENGTH)+1;
  2720.         ptr = (len<pos+LINELENGTH-1) ? len : pos+LINELENGTH-1;
  2721.         for(ii=1;ii<=nseqs;++ii) {
  2722.                         i=output_index[ii];
  2723.             for(j=pos;j<=ptr;++j) {
  2724.                 val=seq_array[i][j];
  2725.                 if((val == -3) || (val == 253)) break;
  2726.                 else if((val < 0) || (val > max_aa))
  2727.                                         seq1[j]='-';
  2728.                 else {
  2729.                     if(dnaflag)
  2730.                         seq1[j]=nucleic_acid_order[val];
  2731.                     else
  2732.                         seq1[j]=amino_acid_codes[val];
  2733.                 }
  2734.             }
  2735.             for(;j<=ptr;++j) seq1[j]='-';
  2736.             strncpy(temp,&seq1[pos],ptr-pos+1);
  2737.             temp[ptr-pos+1]=EOS;
  2738.             fprintf(clusout,"%-15s %s\n",names[i],temp);
  2739.         }
  2740.     
  2741.         for(i=pos;i<=ptr;++i) {
  2742.             seq1[i]=' ';
  2743.             ident=0;
  2744.             for(j=1;res_cat[j-1]!=NULL;j++) catident[j-1] = 0;
  2745.             for(j=1;j<=nseqs;++j) {
  2746.                 if((seq_array[1][i] >=0) && 
  2747.                    (seq_array[1][i] <= max_aa)) {
  2748.                     if(seq_array[1][i] == seq_array[j][i])
  2749.                     ++ident;
  2750.                     for(k=1;res_cat[k-1]!=NULL;k++) {
  2751.                             for(l=0;c=res_cat[k-1][l];l++) {
  2752.                             if (amino_acid_codes[seq_array[j][i]]==c)
  2753.                             {
  2754.                                 catident[k-1]++;
  2755.                                 break;
  2756.                             }
  2757.                         }
  2758.                     }
  2759.                 }
  2760.             }
  2761.             if(ident==nseqs)
  2762.                 seq1[i]='*';
  2763.             else if (!dnaflag) {
  2764.                 for(k=1;res_cat[k-1]!=NULL;k++) {
  2765.                     if (catident[k-1]==nseqs) {
  2766.                         seq1[i]='.';
  2767.                         break;
  2768.                     }
  2769.                 }
  2770.             }
  2771.         }
  2772.         strncpy(temp,&seq1[pos],ptr-pos+1);
  2773.         temp[ptr-pos+1]=EOS;
  2774.         fprintf(clusout,"                %s\n\n",temp);
  2775.     }
  2776.  
  2777. /* DES    ckfree(output_index); */
  2778.     
  2779. }
  2780.  
  2781.  
  2782.  
  2783.  
  2784.  
  2785.  
  2786. static void gcg_out(FILE *gcgout, int len)
  2787. {
  2788. /*        static char *aacids = "XCSTPAGNDEQHRKMILVFYW";*/
  2789. /*    static char *nbases = "XACGT";    */
  2790.     char seq[MAXLEN+1], residue;
  2791.     int all_checks[MAXN+1];
  2792.     int i,ii,j,k,val,check,chunks,block,pos1,pos2;    
  2793.     long grand_checksum;
  2794.     
  2795.     for(i=1; i<=nseqs; i++) {
  2796.         for(j=1; j<=len; j++) {
  2797.             val = seq_array[i][j];
  2798.             if((val == -3) || (val == 253)) break;
  2799.             else if((val < 0) || (val > max_aa))
  2800.                 residue = '.';
  2801.                         else {
  2802.                 if(dnaflag)
  2803.                     residue = nucleic_acid_order[val];
  2804.                 else
  2805.                     residue = amino_acid_codes[val];
  2806.             }
  2807.             seq[j] = residue;
  2808.         }
  2809.         all_checks[i] = SeqGCGCheckSum(seq+1, len);
  2810.     }    
  2811.  
  2812.     grand_checksum = 0;
  2813.     for(i=1; i<=nseqs; i++) grand_checksum += all_checks[output_index[i]];
  2814.     grand_checksum = grand_checksum % 10000;
  2815.         fprintf(gcgout,"PileUp\n\n");
  2816.     fprintf(gcgout,"\n\n   MSF:%5d  Type: ",(pint)len);
  2817.     if(dnaflag)
  2818.         fprintf(gcgout,"N");
  2819.     else
  2820.         fprintf(gcgout,"P");
  2821.     fprintf(gcgout,"    Check:%6ld   .. \n\n", (long)grand_checksum);
  2822.     for(ii=1; ii<=nseqs; ii++)  {
  2823.                 i = output_index[ii];
  2824. /*        for(j=0; j<MAXNAMES; j++) 
  2825.             if(names[i][j] == ' ')  names[i][j] = '_';     */
  2826.         fprintf(gcgout,
  2827.             " Name: %-15s oo  Len:%5d  Check:%6ld  Weight:  1.00\n",
  2828.             names[i],(pint)len,(long)all_checks[i]);
  2829.         }
  2830.     fprintf(gcgout,"\n//\n");  
  2831.  
  2832.     chunks = len/GCG_LINELENGTH;
  2833.     if(len % GCG_LINELENGTH != 0) ++chunks;
  2834.  
  2835.     for(block=1; block<=chunks; block++) {
  2836.         fprintf(gcgout,"\n\n");
  2837.         pos1 = ((block-1) * GCG_LINELENGTH) + 1;
  2838.         pos2 = (len<pos1+GCG_LINELENGTH-1)? len : pos1+GCG_LINELENGTH-1;
  2839.         for(ii=1; ii<=nseqs; ii++) {
  2840.                         i = output_index[ii];
  2841.             fprintf(gcgout,"\n%-15s ",names[i]);
  2842.             for(j=pos1, k=1; j<=pos2; j++, k++) {
  2843. /*
  2844.     JULIE -
  2845.     check for short sequences - pad out with '.' characters to end of alignment
  2846. */
  2847.                 if (j<=seqlen_array[i])
  2848.                     val = seq_array[i][j];
  2849.                 else val = -3;
  2850.                 if((val == -3) || (val == 253))
  2851.                     residue = '.';
  2852.                 else if((val < 0) || (val > max_aa))
  2853.                     residue = '.';
  2854.                 else {
  2855.                     if(dnaflag)
  2856.                         residue = nucleic_acid_order[val];
  2857.                     else
  2858.                         residue = amino_acid_codes[val];
  2859.                 }
  2860.                 fprintf(gcgout,"%c",residue);
  2861.                 if(j % 10 == 0) fprintf(gcgout," ");
  2862.             }
  2863.         }
  2864.     }
  2865. /* DES    ckfree(output_index); */
  2866.     fprintf(gcgout,"\n\n");
  2867. }
  2868.  
  2869.  
  2870.  
  2871. static void phylip_out(FILE *phyout, int len)
  2872. {
  2873. /*      static char *aacids = "XCSTPAGNDEQHRKMILVFYW";*/
  2874. /*        static char *nbases = "XACGT";    */
  2875.     char residue;
  2876.     int i,ii,j,k,val,chunks,block,pos1,pos2;    
  2877.     
  2878.     len = seqlen_array[1];
  2879.  
  2880.  
  2881.     chunks = len/GCG_LINELENGTH;
  2882.     if(len % GCG_LINELENGTH != 0) ++chunks;
  2883.  
  2884.     fprintf(phyout,"%6d %6d",(pint)nseqs,(pint)len);
  2885.  
  2886.     for(block=1; block<=chunks; block++) {
  2887.         pos1 = ((block-1) * GCG_LINELENGTH) + 1;
  2888.         pos2 = (len<pos1+GCG_LINELENGTH-1)? len : pos1+GCG_LINELENGTH-1;
  2889.         for(ii=1; ii<=nseqs; ii++)  {
  2890.                         i = output_index[ii];
  2891.             if(block == 1) 
  2892.                 fprintf(phyout,"\n%-10s ",names[i]);
  2893.             else
  2894.                 fprintf(phyout,"\n           ");
  2895.             for(j=pos1, k=1; j<=pos2; j++, k++) {
  2896.                 val = seq_array[i][j];
  2897.                 if((val == -3) || (val == 253))
  2898.                     break;
  2899.                 else if((val < 0) || (val > max_aa))
  2900.                     residue = '-';
  2901.                 else {
  2902.                     if(dnaflag)
  2903.                         residue = nucleic_acid_order[val];
  2904.                     else
  2905.                         residue = amino_acid_codes[val];
  2906.                 }
  2907.                 fprintf(phyout,"%c",residue);
  2908.                 if(j % 10 == 0) fprintf(phyout," ");
  2909.             }
  2910.         }
  2911.         fprintf(phyout,"\n");
  2912.     }
  2913. /* DES    ckfree(output_index); */
  2914. }
  2915.  
  2916.  
  2917.  
  2918.  
  2919.  
  2920. static void nbrf_out(FILE *nbout, int len)
  2921. {
  2922. /*      static char *aacids = "XCSTPAGNDEQHRKMILVFYW";*/
  2923. /*        static char *nbases = "XACGT";    */
  2924.     char seq[MAXLEN+1], residue;
  2925.     int i,ii,j,val, slen;    
  2926.     
  2927.     for(ii=1; ii<=nseqs; ii++) {
  2928.                 i = output_index[ii];
  2929.         fprintf(nbout, dnaflag ? ">DL;" : ">P1;");
  2930.         fprintf(nbout, "%s\n%s\n", names[i], titles[i]);
  2931.         slen = 0;
  2932.         for(j=1; j<=len; j++) {
  2933.             val = seq_array[i][j];
  2934.             if((val == -3) || (val == 253))
  2935.                 break;
  2936.             else if((val < 0) || (val > max_aa))
  2937.                 residue = '-';
  2938.             else {
  2939.                 if(dnaflag)
  2940.                     residue = nucleic_acid_order[val];
  2941.                 else
  2942.                     residue = amino_acid_codes[val];
  2943.             }
  2944.             seq[j] = residue;
  2945.             slen++;
  2946.         }
  2947.         for(j=1; j<=slen; j++) {
  2948.             fprintf(nbout,"%c",seq[j]);
  2949.             if((j % LINELENGTH == 0) || (j == slen)) 
  2950.                 fprintf(nbout,"\n");
  2951.         }
  2952.         fprintf(nbout,"*\n");
  2953.     }    
  2954. /* DES    ckfree(output_index);  */
  2955. }
  2956.  
  2957.  
  2958. static void gde_out(FILE *gdeout, int len)
  2959. {
  2960. /*      static char *aacids = "XCSTPAGNDEQHRKMILVFYW";*/
  2961. /*        static char *nbases = "XACGT";    */
  2962.     char seq[MAXLEN+1], residue;
  2963.     int i,ii,j,val, slen;    
  2964.     
  2965.     for(ii=1; ii<=nseqs; ii++) {
  2966.                 i = output_index[ii];
  2967.         fprintf(gdeout, dnaflag ? "#" : "%%");
  2968.         fprintf(gdeout, "%s\n", names[i]);
  2969.         slen = 0;
  2970.         for(j=1; j<=len; j++) {
  2971.             val = seq_array[i][j];
  2972.             if((val == -3) || (val == 253))
  2973.                 break;
  2974.             else if((val < 0) || (val > max_aa))
  2975.                 residue = '-';
  2976.             else {
  2977.                 if(dnaflag)
  2978.                     residue = nucleic_acid_order[val];
  2979.                 else
  2980.                     residue = amino_acid_codes[val];
  2981.             }
  2982.             if (lowercase)
  2983.                 seq[j] = (char)tolower((int)residue);
  2984.             else
  2985.                 seq[j] = residue;
  2986.             slen++;
  2987.         }
  2988.         for(j=1; j<=slen; j++) {
  2989.             fprintf(gdeout,"%c",seq[j]);
  2990.             if((j % LINELENGTH == 0) || (j == slen)) 
  2991.                 fprintf(gdeout,"\n");
  2992.         }
  2993.     }    
  2994. /* DES    ckfree(output_index); */
  2995. }
  2996.  
  2997.  
  2998. static Boolean open_alignment_output(char *path)
  2999. {
  3000.  
  3001.     if(!output_clustal && !output_nbrf && !output_gcg &&
  3002.          !output_phylip && !output_gde) {
  3003.                 error("You must select an alignment output format");
  3004.                 return FALSE;
  3005.         }
  3006.  
  3007.     if(output_clustal) 
  3008.         if (explicit_outfile) {
  3009.             strcpy(clustal_outname,outfile_name);
  3010.             if((clustal_outfile = open_explicit_file(
  3011.             clustal_outname))==NULL) return FALSE;
  3012.         }
  3013.         else {
  3014. /* DES DEBUG 
  3015. fprintf(stdout,"\n\n path = %s\n clustal_outname = %s\n\n",
  3016. path,clustal_outname);
  3017. */
  3018.                if((clustal_outfile = open_output_file(
  3019.                 "\nEnter a name for the CLUSTAL output file ",path,
  3020.             clustal_outname,"aln"))==NULL) return FALSE;
  3021. /* DES DEBUG 
  3022. fprintf(stdout,"\n\n path = %s\n clustal_outname = %s\n\n",
  3023. path,clustal_outname);
  3024. */
  3025.         }
  3026.     if(output_nbrf) 
  3027.         if (explicit_outfile) {
  3028.             strcpy(nbrf_outname,outfile_name);
  3029.             if((nbrf_outfile = open_explicit_file(
  3030.             nbrf_outname))==NULL) return FALSE;
  3031.         }
  3032.         else
  3033.             if((nbrf_outfile = open_output_file(
  3034.                 "\nEnter a name for the NBRF/PIR output file",path,
  3035.             nbrf_outname,"pir"))==NULL) return FALSE;
  3036.     if(output_gcg) 
  3037.         if (explicit_outfile) {
  3038.             strcpy(gcg_outname,outfile_name);
  3039.             if((gcg_outfile = open_explicit_file(
  3040.             gcg_outname))==NULL) return FALSE;
  3041.         }
  3042.         else
  3043.             if((gcg_outfile = open_output_file(
  3044.                 "\nEnter a name for the GCG output file     ",path,
  3045.             gcg_outname,"msf"))==NULL) return FALSE;
  3046.     if(output_phylip) 
  3047.         if (explicit_outfile) {
  3048.             strcpy(phylip_outname,outfile_name);
  3049.             if((phylip_outfile = open_explicit_file(
  3050.             phylip_outname))==NULL) return FALSE;
  3051.         }
  3052.         else
  3053.             if((phylip_outfile = open_output_file(
  3054.                 "\nEnter a name for the PHYLIP output file  ",path,
  3055.             phylip_outname,"phy"))==NULL) return FALSE;
  3056.     if(output_gde) 
  3057.         if (explicit_outfile) {
  3058.             strcpy(gde_outname,outfile_name);
  3059.             if((gde_outfile = open_explicit_file(
  3060.             gde_outname))==NULL) return FALSE;
  3061.         }
  3062.         else
  3063.             if((gde_outfile = open_output_file(
  3064.                 "\nEnter a name for the GDE output file     ",path,
  3065.             gde_outname,"gde"))==NULL) return FALSE;
  3066.     return TRUE;
  3067. }
  3068.  
  3069.  
  3070.  
  3071.  
  3072.  
  3073. static void create_alignment_output(int length)
  3074. {
  3075.     if(output_clustal) {
  3076.         clustal_out(clustal_outfile, length);
  3077.         fclose(clustal_outfile);
  3078.         fprintf(stdout,"\nCLUSTAL-Alignment file created  [%s]\n",clustal_outname);
  3079.     }
  3080.     if(output_nbrf)  {
  3081.         nbrf_out(nbrf_outfile, length);
  3082.         fclose(nbrf_outfile);
  3083.         fprintf(stdout,"\nNBRF/PIR-Alignment file created [%s]\n",nbrf_outname);
  3084.     }
  3085.     if(output_gcg)  {
  3086.         gcg_out(gcg_outfile, length);
  3087.         fclose(gcg_outfile);
  3088.         fprintf(stdout,"\nGCG-Alignment file created      [%s]\n",gcg_outname);
  3089.     }
  3090.     if(output_phylip)  {
  3091.         phylip_out(phylip_outfile, length);
  3092.         fclose(phylip_outfile);
  3093.         fprintf(stdout,"\nPHYLIP-Alignment file created   [%s]\n",phylip_outname);
  3094.     }
  3095.     if(output_gde)  {
  3096.         gde_out(gde_outfile, length);
  3097.         fclose(gde_outfile);
  3098.         fprintf(stdout,"\nGDE-Alignment file created      [%s]\n",gde_outname);
  3099.     }
  3100. }
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.  
  3107. static void reset(void)   /* remove gaps from older alignments (code = gap_pos1) */
  3108. {              /* EXCEPT for gaps that were INPUT with the seqs.*/
  3109.     register int i,j,sl;                /* which have  code = gap_pos2  */
  3110.     
  3111.     for(i=1;i<=nseqs;++i) {
  3112.         sl=0;
  3113.         for(j=1;j<=seqlen_array[i];++j) {
  3114.             if(seq_array[i][j] == gap_pos1) continue;
  3115.             ++sl;
  3116.             seq_array[i][sl]=seq_array[i][j];
  3117.         }
  3118.         seqlen_array[i]=sl;
  3119.     }
  3120. }
  3121.  
  3122. static int find_match(char *probe, char *list[], int n)
  3123. {
  3124.     int i,j,len;
  3125.     int count,match;
  3126.  
  3127.     len = strlen(probe);
  3128.     for (i=0;i<len;i++) {
  3129.         count = 0;
  3130.         for (j=0;j<n;j++) {
  3131.             if (probe[i] == list[j][i]) {
  3132.                 match = j;
  3133.                 count++;
  3134.             }
  3135.         }
  3136.         if (count == 1) return(match);
  3137.     }
  3138.     return(-1);
  3139. }
  3140.  
  3141. static void create_parameter_output(void)
  3142. {
  3143.     int i, fd;
  3144.     char parname[FILENAMELEN+1], temp[FILENAMELEN+1];
  3145.     char path[FILENAMELEN+1];
  3146.     FILE *parout;
  3147.  
  3148.         get_path(seqname,path);
  3149.         strcpy(parname,path);
  3150.         strcat(parname,"par");
  3151.  
  3152.     if(usemenu) {
  3153.             fprintf(stdout,"\nEnter a name for the parameter output file [%s]: ",
  3154.                                            parname);
  3155.                    gets(temp);
  3156.                    if(*temp != EOS)
  3157.                            strcpy(parname,temp);
  3158.            }
  3159.  
  3160. /* create a file with execute permissions first */
  3161.     remove(parname);
  3162. /*
  3163.     fd = creat(parname, 0777);
  3164.     close(fd);
  3165. */
  3166.  
  3167.         if((parout = open_explicit_file(parname))==NULL) return;
  3168.  
  3169.         fprintf(parout,"clustalw \\\n");
  3170.     if (!empty && profile1_empty) fprintf(parout,"/infile=%s \\\n",seqname);
  3171.     if (!profile1_empty) fprintf(parout,"/profile1=%s\\\n",profile1_name);
  3172.     if (!profile2_empty) fprintf(parout,"/profile2=%s \\\n",profile2_name);
  3173.     if (dnaflag == TRUE) fprintf(parout,"/type=dna \\\n");
  3174.     else                 fprintf(parout,"/type=protein \\\n");
  3175.  
  3176.     if (quick_pairalign) {
  3177.         fprintf(parout,"/quicktree \\\n");
  3178.         fprintf(parout,"/ktuple=%d \\\n",(pint)ktup);
  3179.              fprintf(parout,"/window=%d \\\n",(pint)window);
  3180.              fprintf(parout,"/pairgap=%d \\\n",(pint)wind_gap);
  3181.              fprintf(parout,"/topdiags=%d \\\n",(pint)signif);    
  3182.              if (percent) fprintf(parout,"/score=percent \\\n");      
  3183.              else         fprintf(parout,"/score=absolute \\\n");      
  3184.     }
  3185.     else {
  3186.         if (!dnaflag) {
  3187.             fprintf(parout,"/pwmatrix=%s \\\n",pw_mtrxname);
  3188.             fprintf(parout,"/pwgapopen=%.2f \\\n",prot_pw_go_penalty);
  3189.             fprintf(parout,"/pwgapext=%.2f \\\n",prot_pw_ge_penalty);
  3190.         }
  3191.         else {
  3192.             fprintf(parout,"/pwgapopen=%.2f \\\n",pw_go_penalty);
  3193.             fprintf(parout,"/pwgapext=%.2f \\\n",pw_ge_penalty);
  3194.         }
  3195.     }
  3196.  
  3197.     if (!dnaflag) {
  3198.         fprintf(parout,"/matrix=%s \\\n",mtrxname);
  3199.         fprintf(parout,"/gapopen=%.2f \\\n",prot_gap_open);
  3200.         fprintf(parout,"/gapext=%.2f \\\n",prot_gap_extend);
  3201.     }
  3202.     else {
  3203.         fprintf(parout,"/gapopen=%.2f \\\n",dna_gap_open);
  3204.         fprintf(parout,"/gapext=%.2f \\\n",dna_gap_extend);
  3205.     }
  3206.  
  3207.     fprintf(parout,"/maxdiv=%d \\\n",(pint)divergence_cutoff);
  3208.     if (!use_endgaps) fprintf(parout,"/endgaps \\\n");    
  3209.  
  3210.     if (!dnaflag) {
  3211.              if (neg_matrix) fprintf(parout,"/negative \\\n");   
  3212.              if (no_pref_penalties) fprintf(parout,"/nopgap \\\n");     
  3213.              if (no_hyd_penalties) fprintf(parout,"/nohgap \\\n");     
  3214.             fprintf(parout,"/hgapresidues=%s \\\n",hyd_residues);
  3215.              fprintf(parout,"/gapdist=%d \\\n",(pint)gap_dist);     
  3216.     }
  3217.     else {
  3218.              if (!is_weight) fprintf(parout,"/transitions \\\n");
  3219.     }
  3220.  
  3221.          if (output_gcg) fprintf(parout,"/output=gcg \\\n");
  3222.          else if (output_gde) fprintf(parout,"/output=gde \\\n");
  3223.          else if (output_nbrf) fprintf(parout,"/output=pir \\\n");
  3224.          else if (output_phylip) fprintf(parout,"/output=phylip \\\n");
  3225.          if (explicit_outfile) fprintf(parout,"/outfile=%s \\\n",outfile_name);
  3226.          if (output_order==ALIGNED) fprintf(parout,"/outorder=aligned \\\n");  
  3227.          else                      fprintf(parout,"/outorder=input \\\n");  
  3228.          if (output_gde)
  3229.         if (lowercase) fprintf(parout,"/case=lower \\\n");
  3230.         else           fprintf(parout,"/case=upper \\\n");
  3231.  
  3232.  
  3233.         fprintf(parout,"/interactive\n");
  3234.  
  3235.     fclose(parout);
  3236. /*
  3237.       if (kimura) fprintf(parout,"/kimura \\\n");     
  3238.     if (tossgaps) fprintf(parout,"/tossgaps \\\n");   
  3239.     fprintf(parout,"/seed=%d \\\n",(pint)boot_ran_seed);
  3240.     fprintf(parout,"/bootstrap=%d \\\n",(pint)boot_ntrials);
  3241. */
  3242. }
  3243.  
  3244.